Problems with Datenum / Datestr to convert times and dates to serial time and dates
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
per isakson
le 7 Juil 2012
Modifié(e) : per isakson
le 7 Juil 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
0 commentaires
Voir également
Catégories
En savoir plus sur Dates and Time dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!