how to correct time ?

6 visualizaciones (últimos 30 días)
Lilya
Lilya el 13 de En. de 2019
Comentada: Lilya el 13 de En. de 2019
Hi all,
the from netCDF file shows:
time
Size: 365x1
Dimensions: time
Datatype: double
Attributes:
long_name = 'Time (hours since 1950-01-01)'
standard_name = 'time'
calendar = 'gregorian'
units = 'hours since 1950-01-01 00:00:00'
axis = 'T'
_ChunkSizes = 1
_CoordinateAxisType = 'Time'
valid_min = 534732
valid_max = 543468
and I want to get the time corrected to matlab time, I used the commands below:
stime = double(time);
stime = stime + datenum(1950,1,1,0,0); % create a time array in matlab time
dtime = datevec(stime);
and here is the result (not correct):
dtime = 534732
534756
534780
534804
534828
534852];
I want to correct it to MATLAB time. Any help will be appreciated.
Thanks

Respuesta aceptada

Walter Roberson
Walter Roberson el 13 de En. de 2019
Serial date numbers are in days; entries from the file are in hours. You are taking a base time in days (a good step in itself) and adding hours as if they were days.
There is a trick available here: whenever you populate a datevec or datetime field with a higher value than the normal per-cycle maximum, then the extra is carried up to as many fields above as necessary.
dtime = datetime(1950, 1, 1, time, 0, 0)
Looks like you would get 01-Jan-2011 12:00:00 to 31-Dec-2011 12:00:00
  1 comentario
Lilya
Lilya el 13 de En. de 2019
Thank you a bunch!
I really appreciate your help Sir Walter

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.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by