Problems with Datenum / Datestr to convert times and dates to serial time and dates

2 Ansichten (letzte 30 Tage)
Hello fellow Matlabers,
I have a problem converting times and dates to serial times and dates. I have a matrix containing times and dates, just like this:
'17:05:38' '06/27/12'
'17:05:42' '06/27/12'
...
I need to convert this matrix into one that looks just like this:
'0.712245370' '39625'
'0.712291667' '39625'
....
This is the code I am using so far:
sernums = [datestr( data(2) ), datestr( data(1) )]; output = [sernums data{3} dataC{4}];
... and here is the error I am seeing:
??? Error using ==> datestr at 180 Cannot convert input into specified date string. DATENUM failed..
Does anybody have an idea on what is causing my error? Any help would be greatly appreciated.
Thank you,
Nils

Antworten (1)

per isakson
per isakson am 7 Jul. 2012
Bearbeitet: per isakson am 7 Jul. 2012
Try
data = {'17:05:38', '06/27/12'
'17:05:42', '06/27/12' };
out = [ datenum(data(:,1),'HH:MM:SS')-datenum('00:00:00','HH:MM:SS') ...
, datenum(data(:,2),'mm/dd/yy') ];
I assume that you want a numerical output rather than a cell array of strings.
With R2012a
>> datestr( datenum('00:00:00','HH:MM:SS') )
ans =
01-Jan-2012

Kategorien

Mehr zu Dates and Time finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by