Using the new datetime structure within datasets
15 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Jesse Blocher
le 24 Fév 2015
Commenté : Jesse Blocher
le 24 Fév 2015
I have a dataset with date variables as datenums. I'd like to convert them to the new datetime datatype. Here is what I did:
ds.newdate = datetime(ds.olddate,'ConvertFrom','datenum');
This is what I get:
ds
ans =
olddate newdate
734138 [1x1 datetime]
This isn't useful. What I want is this:
ds
ans =
olddate newdate
734138 31-Dec-2009
There is some sort of sub-indexing going on where I have to go another level deeper to access my date variable. How do I access it directly in the dataset?
0 commentaires
Réponse acceptée
Peter Perkins
le 24 Fév 2015
Jesse, have you tried using a table rather than a dataset? A table is, roughly speaking, a replacement for dataset that is available in core MATLAB (rather than just the Statistics Toolbox) since R2013b. Since you are using datetime, you must have R2014b.
The [1x1 datetime] that you are seeing is really just a display artifact, and ds.newdate is a datetime. But table provides the display you are looking for:
>> t = table((734138:734140)','VariableNames',{'OldDate'})
t =
OldDate
__________
7.3414e+05
7.3414e+05
7.3414e+05
>> t.NewDate = datetime(t.OldDate,'ConvertFrom','datenum')
t =
OldDate NewDate
__________ ____________________
7.3414e+05 31-Dec-2009 00:00:00
7.3414e+05 01-Jan-2010 00:00:00
7.3414e+05 02-Jan-2010 00:00:00
Hope this helps.
Plus de réponses (0)
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!