convert narr model data time to datevec or datestr

조회 수: 2 (최근 30일)
Leyon
Leyon 2014년 7월 10일
댓글: Leyon 2014년 7월 11일
I have a set of model data that has time attributes:
Attributes:
units = 'hours since 1800-1-1 00:00:0.0'
long_name = 'Time'
axis = 'T'
standard_name = 'time'
coordinate_defines = 'start'
delta_t = '0000-00-01 00:00:00'
actual_range = [1.74e+06 1.75e+06]
avg_period = '0000-00-01 00:00:00'
When I pull a sample time such as time(1:5) I get:
1744392
1744416
1744440
1744464
1744488
When trying to convert to date string using datestr(time(1)) I get: 25-Dec-4775. I try putting in a pivot year of 1800 but still get the same result. What am I doing wrong? The result should be Jan 1st 1999.
  댓글 수: 2
Star Strider
Star Strider 2014년 7월 10일
How are you calculating 'time'?
Leyon
Leyon 2014년 7월 10일
I am not calculating time. The time variable was part of the netcdf file with the attributes shown. A copy of the data (68mb) can be downloaded from:

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2014년 7월 10일
>> dn1800=datenum(1800,1,1) % baseline point in Matlab datenum
dn1800 =
657438
>> datestr(dn1800+1744392/24) % add that many hours in days...
ans =
01-Jan-1999
The better way...
>> datestr(addtodate(dn1800,1744392,'hour'))
ans =
01-Jan-1999
>>
  댓글 수: 2
Leyon
Leyon 2014년 7월 10일
Thanks for the assist. Was becoming quite bothersome.
Leyon
Leyon 2014년 7월 11일
how would I go about entering a regular date 1999,1,1 and get the datenum 1744392? I tried reversing your process but that doesn't work

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

dpb
dpb 2014년 7월 11일
Seems ok to me...
>> (datenum(1999,1,1)-dn1800)*24
ans =
1744392
Convert the days to hours from the reference point.
  댓글 수: 1
Leyon
Leyon 2014년 7월 11일
Thanks. Guess my algebra is rusty. Been a long day.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Time Series Objects에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by