how to correct time ?

17 次查看(过去 30 天)
Lilya
Lilya 2019-1-13
评论: Lilya 2019-1-13
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

采纳的回答

Walter Roberson
Walter Roberson 2019-1-13
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 个评论
Lilya
Lilya 2019-1-13
Thank you a bunch!
I really appreciate your help Sir Walter

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by