how to correct time ?

9 views (last 30 days)
Lilya
Lilya on 13 Jan 2019
Commented: Lilya on 13 Jan 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

Accepted Answer

Walter Roberson
Walter Roberson on 13 Jan 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 Comment
Lilya
Lilya on 13 Jan 2019
Thank you a bunch!
I really appreciate your help Sir Walter

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by