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

2 vues (au cours des 30 derniers jours)
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

Réponse acceptée

Rik
Rik le 25 Août 2020
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 commentaires
Rik
Rik le 26 Août 2020
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 le 29 Août 2020
oh ya. now the problem solved. Thank you Sir and everyone :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Dates and Time dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by