Convert the first datenum column of a double variable

5 次查看(过去 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 个评论
Pietro
Pietro 2023-5-3
Thanks, in the end I converted the array to a table then replacing the first column with a datetime vector.. Don't know if this is the quickest approach by the way
dpb
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 CenterFile Exchange 中查找有关 Dates and Time 的更多信息

产品


版本

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by