From: Allan on
Hi all,

I am trying to create a vector with all the hours from 1/1/2004 00:00 to 1/1/2009 00:00.

I have used datenum and linspace but the hours are shifted by few seconds.
What to do?


Is there an error in datenum or why is
>> datenum(2004, 31,12,0,0,0)-datenum(2004,1,1,0,0,0)
ans =
923

and

>> datestr(datenum(2004, 31,12,0,0,0))
ans =
12-Jul-2006

/Allan
From: Vadim Teverovsky on
Probably because you have asked for the 12th day of the 31st month of 2004.
That is the same as 12 th day of the 7th month of 2006.

As far as precision, when I try:
a = datenum(2004,1,1,0,0,0)
b = datenum(2009,1,1,0,0,0)

c = linspace(a,b, (b-a)*24+1);
datestr(c)


I seem to get the right values.


"Allan " <alg(a)energinet.dl> wrote in message
news:hbp97n$e1i$1(a)fred.mathworks.com...
> Hi all,
>
> I am trying to create a vector with all the hours from 1/1/2004 00:00 to
> 1/1/2009 00:00.
>
> I have used datenum and linspace but the hours are shifted by few seconds.
> What to do?
>
>
> Is there an error in datenum or why is
>>> datenum(2004, 31,12,0,0,0)-datenum(2004,1,1,0,0,0)
> ans =
> 923
>
> and
>
>>> datestr(datenum(2004, 31,12,0,0,0))
> ans =
> 12-Jul-2006
>
> /Allan