Double to cell conversion difficulties
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
I have a cell array called temp which stores two columns of dates. Each date is currently stored as a char string (eg: 28/12/2808) within a cell. I'd like to convert these to datenumbers for plotting and sorting.However, when I do this:
temp(:,1)=datenum(temp(:,1),'dd/mm/yy');
I get:
"Conversion to cell from double is not possible."
I've tried drinking several cups of coffee but that hasn't helped either. I assume I am missing { } somewhere but I just can't figure out where. num2cell seems to work but it's not very elegant.
0 commentaires
Réponses (2)
Bård Skaflestad
le 26 Jan 2012
There is a slight misunderstanding in the way you use datenum. Specifically, datenum(temp(:,1),'dd/mm/yy') returns a double for each element in the cell array temp(:,1). However, you cannot directly assign individual double|s to the corresponding element of |temp(:,1).
One way to achieve the (presumably) desired effect is to use the num2cell function like
temp(:,1) = num2cell(datenum(temp(:,1), 'dd/mm/yy'))
but there may be other techniques that solve the larger problem you're trying to solve more directly.
0 commentaires
Jan
le 26 Jan 2012
When you want to use the date numbers for plotting and sorting, they must be stored as a numerical vector:
temp2(:,1) = datenum(temp(:,1), 'dd/mm/yy');
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!