import时间 matlab_在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

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

解决方案

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值