Using the new datetime structure within datasets
조회 수: 14 (최근 30일)
이전 댓글 표시
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
채택된 답변
Peter Perkins
2015년 2월 24일
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Dates and Time에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!