how to correct time ?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
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
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Dates and Time 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!