Convert the first datenum column of a double variable
1 次查看(过去 30 天)
显示 更早的评论
Hi all,
I am struggling to find a way to convert the first column (which is a datenum) of a double array because I cannot neither replace it with a datestr column nor with a datetime one. The idea would be to output the same double array as before but with dates in DD/MM/YYYY format in place of the general data numerical codes.
Thanks in advance
3 个评论
dpb
2023-5-3
The shortest route to the end result would depend upon the path by which you got to the original starting point which we don't know.
The shortest way from a double array to would be as you did; it's not possible to provide a conversion function as part of the array2table path; that's not a bad idea for an enhancement, actually.
Well, there is one alternate way one could write it, but it's probably better done as the above, but you could do something like
tData=[table(datetime(x(:,1),'convertfrom','datenum')) array2table(x(:,2:end))];
The other alternative would be to use a timetable instead--very similar to a table except the time variable is a property instead of an additional table variable. Everything in a table can be done with a timetable but a timetable has a few additional methods/functions with respect to the time that can be very useful if one of those particular things needs doing -- retime is one particularly nice feature.
ttData=array2timetable(x(:,2:end),'RowTimes',x(:,1));
回答(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!