How to read the text file start from 7th line and convert the date into datenum?
1 次查看(过去 30 天)
显示 更早的评论
Hi everyone. I need to read the text starting from 7th line of text file until the end of data. And the date need to be converted into datenum. can anyone help me to solve this matter.
The text file looks like this:
Lat: 6.4931, Lon: 99.6067, Parameter: z(m)
Depth (m): 22.45
Constituents included: m2 s2 k1 o1
Time start: 00:00, 1. 1.1993
Time step (min): 60.00
Time Series length (hours):236664
01-Jan-1993 00:00:00 -0.0946
01-Jan-1993 01:00:00 -0.3369
01-Jan-1993 02:00:00 -0.5110
01-Jan-1993 03:00:00 -0.5776
01-Jan-1993 04:00:00 -0.5228
01-Jan-1993 05:00:00 -0.3611
01-Jan-1993 06:00:00 -0.1310
01-Jan-1993 07:00:00 0.1149
01-Jan-1993 08:00:00 0.3225
0 个评论
采纳的回答
Rik
2020-8-25
Assuming each line is a cell:
%01-Jan-1993 00:00:00
% 11111111112
%12345678901234567890
% date is in the first 20 chars
data={'01-Jan-1993 00:00:00 -0.0946';
'01-Jan-1993 01:00:00 -0.3369';
'01-Jan-1993 02:00:00 -0.5110';
'01-Jan-1993 03:00:00 -0.5776';
'01-Jan-1993 04:00:00 -0.5228';
'01-Jan-1993 05:00:00 -0.3611';
'01-Jan-1993 06:00:00 -0.1310';
'01-Jan-1993 07:00:00 0.1149';
'01-Jan-1993 08:00:00 0.3225'};
d=cellfun(@(x) datenum(x(1:20)),data);
6 个评论
Rik
2020-8-26
You need to use a loop, or hide the loop with cellfun:
dtn = cellfun(@(ymd,hms)datenum([ymd ' ' hms],'dd-mm-yyyy HH:MM:SS'),A{1},A{2});
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Text Files 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!