user1297712
user1297712

Reputation: 73

How to convert dates to numbers in Matlab

I have some variables like these:

a(1)=00:26:00
a(2)=744:32:00
a(3)=8040:33:00

I want to convert them to numbers, so I use the datenum command.
The biggest number should be 8040:33:00, but look what happens.

datenum(a([1 2 3]))

ans =

1.0e+005 *

7.3487
7.3485
7.3486

But if I don´t calculate a(1):

datenum(a([2 3]))

ans =

1.0e+005 *

7.3490
7.3520

That´s the results that I want to get. I think that the problem is that a(2) and a(3) have more than 24hours but I haven´t found any way to solve this problem.
Thanks.

Upvotes: 0

Views: 811

Answers (1)

Christopher Creutzig
Christopher Creutzig

Reputation: 8774

You did not give us your actual input. Having

a(1)=00:26:00
a(2)=744:32:00
a(3)=8040:33:00

means a holds three zeroes. (doc colon explains why.)

If my guess as to what you're actually doing is right, you should be able to use

cellfun(@datenum, a)

I haven't checked deeply, but the behavior looks a bit surprising, indeed. You might want to contact MathWorks Support and file a bug report.

Upvotes: 1

Related Questions