Convert the first datenum column of a double variable

1 回表示 (過去 30 日間)
Pietro
Pietro 2023 年 5 月 3 日
コメント済み: dpb 2023 年 5 月 3 日
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 Center および File ExchangeDates and Time についてさらに検索

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by