Matlab not recognizing dates
6 次查看(过去 30 天)
显示 更早的评论
I have a vector of dates in the format yyyymm, however matlab is not recognizing it for a timetable. Any suggestions?
0 个评论
采纳的回答
Star Strider
2020-11-23
You did not mention how you were importing them.
Try importing them this way:
dv = {'202011'
'202012'}
datetime(dv, 'InputFormat','yyyyMM', 'Format','MM-yyyy')
That works for me.
3 个评论
Star Strider
2020-11-23
dv = [202011
202012];
DT = datetime(num2str(dv), 'InputFormat','yyyyMM', 'Format','MM-yyyy')
producing:
DT =
2×1 datetime array
11-2020
12-2020
Or if you want them in the same format as the input:
DT = datetime(num2str(dv), 'InputFormat','yyyyMM', 'Format','yyyyMM')
producing:
DT =
2×1 datetime array
202011
202012
.
Steven Lord
2020-11-23
You can skip the num2str with a little bit of arithmetic.
x = (202001:202006).'
DT = datetime(100*x+1, 'ConvertFrom', 'yyyymmdd')
更多回答(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!