Convert the first datenum column of a double variable
1 view (last 30 days)
Show older comments
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 Comments
dpb
on 3 May 2023
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));
Answers (0)
See Also
Categories
Find more on Dates and Time in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!