Read data files with specific format in matlab and convert date to matal serial time

ⅰ亾dé卋堺 提交于 2019-12-24 08:59:42

问题


I have a file with the following structure:

29-JUN-1995 09:29:15   21.43   41.03   22.76    8.61 1  307.98    0.85  -9.99000e+002    -999.000000       2.050651       2.323905  4.86704e+015       6.869425       2.099744       2.135507    0.66  849.584  907.607   992
29-JUN-1995 09:29:19   24.62   40.12   20.67  -14.24 0  325.23    0.79  -9.99000e+002    -999.000000       2.095562       2.095562  3.95402e+015      10.898932       2.113338       2.113338    0.00   -1.000 1010.324   992
29-JUN-1995 09:29:21   21.32   40.68   22.56    8.61 1  309.55    0.86  -9.99000e+002    -999.000000       2.047019       2.399543  5.12189e+015       7.569622       2.097261       2.140599    0.30  859.620  898.692   992
02-JUL-1995 09:34:41   23.70   41.51   21.81  -14.24 0  310.98    0.85  -9.99000e+002    -999.000000       2.086681       2.346471  4.68335e+015       7.359228       2.118588       2.149808    0.37  751.101  902.940  1035

I need your help so as to import into a Matlab array and convert the date and time to matlab serial time.


回答1:


Consider the following code. Parsing is done using the TEXTSCAN function:

%# read and parse date file
fid = fopen('data.dat','rt');
C = textscan(fid, ['%s %s ' repmat('%f',1,19)], 'CollectOutput',true);
fclose(fid);

%# convert date/time to serial date number
dt = datenum(strcat(C{1}(:,1), {' '}, C{1}(:,2)), 'dd-mmm-yyyy HH:MM:SS');

%# combine all in one matrix
M = [dt C{2}];



回答2:


>> datenum('29-JUN-1995 09:29:15')

ans =

    7.288393953125000e+005


来源:https://stackoverflow.com/questions/6534866/read-data-files-with-specific-format-in-matlab-and-convert-date-to-matal-serial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!