|||
描述:现有文件acs_05_230715_1811.dat,第1行包含日期与时间信息,内部结构如下:
问题:将日期与时间提取出来,保存成变量,并进行类型转换。
脚本:
------------------------------------------------------------------------------------------------------------
脚本1
fid=fopen('acs_05_230715_1811.dat','r');
line=fgetl(fid); % get the first line
line(find(line=='-'))='/'; % 将-替换成/
DateStr=line(17:35);
DateNum=datenum(DateStr,'mm/dd/yyyy HH:MM:SS'); %same with: DateNum=datenum(DateStr,0);
DateVec=datevec(DateStr,'mm/dd/yyyy HH:MM:SS'); % same with: DateVec=datevec(DateStr,0);
fclose(fid);
-------------------------------------------------------
脚本2
fid=fopen('acs_05_230715_1811.dat','r')
line=fgetl(fid); % get the first line
DateStr=line(17:35);
DateNum=datenum(DateStr,'mm-dd-yyyy HH:MM:SS');
DateVec=datevec(DateStr,'mm-dd-yyyy HH:MM:SS');
fclose(fid);
------------------------------------------------------------------------------------------------------------
脚本文件:
% 运行到第5行:变量line为char型,内容为acs_05_230715_1811.dat的第1行.
% 运行到第6行:变量line为char型,内容为将acs_05_230715_1811.dat第1行的"-"替换成"/".
% 运行到第8行:变量DateStr为char型.
% 运行到第9行:变量DateNum转化为时间的数值格式,double型.
% 运行到第10行:变量DateVec转化为时间的向量格式,double型.
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-5-10 06:41
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社