Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Topic: MATLAB date issue
Replies: 4   Last Post: Sep 16, 2013 1:10 PM

 Messages: [ Previous | Next ]
 Steven Lord Posts: 18,010 Registered: 12/7/04
Re: MATLAB date issue
Posted: Sep 13, 2013 3:26 PM

"Sudip " <majumdersudip@gmail.com> wrote in message
news:l0vn62\$6tj\$1@newscl01ah.mathworks.com...
> I am trying to convert NCEP 2 reanalysis dates to a matlab date format.
> The time-series I am using from NCEP has a starting time : time(1)=
> 1709328;
> with a reference, 'hours since 1800-1-1 00:00:0.0
> (dj=datenum(1800,1,1))''. Matlab uses a different reference date which
> is dm=datenum(1950,1,1)
> when I use the date-shift (dm-dj) and try to use datestr to find the date
> for time(1)=1709328, it gives me datestr(time(1)-dj+dm)
> ans =23-Dec-4829----- which does not make sense.

From what you copied, it sounds like NCEP counts in hours: NCEP time 2 is
one hour later than NCEP time 1.

MATLAB date numbers count in DAYS, not hours: MATLAB date number 2 is one
DAY later than MATLAB date number 1.

> When I use ---datestr(time(1)+dj-dm)
>
> ans =24-Dec-4529---- it does not make sense too.

You're adding apples and oranges and expecting to obtain a pie. What you're
getting instead is a smoothie. [Okay, not the greatest of metaphors.]

> Can anybody help to get the exact time for datenum=1709328

Convert the NCEP hours offset to a day offset and add to the NCEP base time.

T = 1709328;
hoursPerDay = 24;
NCEPbase = datenum(1800, 1, 1);
datestr((T/hoursPerDay) + NCEPbase)

This gives me 1 January 1995. Is that what you expect?

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Date Subject Author
9/13/13 Sudip
9/13/13 James Tursa
9/16/13 Sudip
9/13/13 Steven Lord
9/16/13 Sudip