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

3 visualizaciones (últimos 30 días)
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

Respuesta aceptada

Rik
Rik el 25 de Ag. de 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 comentarios
Rik
Rik el 26 de Ag. de 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 el 29 de Ag. de 2020
oh ya. now the problem solved. Thank you Sir and everyone :)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Dates and Time en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by