Effacer les filtres
Effacer les filtres

Problem converting a cell array of integers to datetime

6 vues (au cours des 30 derniers jours)
JFz
JFz le 1 Fév 2017
Commenté : JFz le 1 Fév 2017
Hi, I have an array if integers (100x1 cell), like 736696, 736697, ....
I try to use b = datetime(a, 'ConvertFrom', 'datenum'), but keep getting error "Input data must be a numeric or a cell array or char matrix containing date/time strings." Why?
Thanks

Réponse acceptée

Jan
Jan le 1 Fév 2017
Modifié(e) : Jan le 1 Fév 2017
If your data is really stored in a cell:
a = {736696, 736697};
v = [a{:}]; % Converted to vector
b = datetime(a, 'ConvertFrom', 'datenum')
Many functions of Matlab expect numeric values in a numeric array and not as a cell. Cells are useful to store elements of different size or type.
  4 commentaires
JFz
JFz le 1 Fév 2017
Thanks. When I ran the above sample code, there is no problem. But when I ran my small table, with it, I keep getting error: Input data must be a numeric or a cell array or char matrix containing date/time strings.
If I ran my code as below it works: out = datetime(myT{1}, 'ConvertFrom', 'datenum') but if I ran my code as: out = datetime(myT, 'ConvertFrom', 'datenum') It gives me the error message. I am quite puzzled.
JFz
JFz le 1 Fév 2017
OK. Found my problem: I have to use a cell2mat to convert my dates first! Thanks for all the help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by