在Matlab中读取具有特定格式的数据文件,并将日期转换为有效的串行时间 [英] Read data files with specific format in matlab and convert date to matal serial time

查看:545
本文介绍了在Matlab中读取具有特定格式的数据文件,并将日期转换为有效的串行时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有以下结构的文件:

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

我需要您的帮助,以便导入到Matlab数组中并将日期和时间转换为matlab串行时间.

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

推荐答案

请考虑以下代码.使用 TEXTSCAN 函数进行解析:

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}];

这篇关于在Matlab中读取具有特定格式的数据文件,并将日期转换为有效的串行时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆