How to read the text file start from 7th line and convert the date into datenum?

조회 수: 2 (최근 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

채택된 답변

Rik
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
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});
hanif hamden
hanif hamden 2020년 8월 29일
oh ya. now the problem solved. Thank you Sir and everyone :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Dates and Time에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by