how to correct time ?

조회 수: 6 (최근 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