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

3 ビュー (過去 30 日間)
hanif hamden
hanif hamden 2020 年 8 月 25 日
コメント済み: hanif hamden 2020 年 8 月 29 日
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 Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by