Add datetime vector which contains NaT to double

4 ビュー (過去 30 日間)
Louise Wilson
Louise Wilson 2020 年 5 月 24 日
回答済み: Eric Sofen 2020 年 6 月 9 日
I have a 2546x7200 matrix and I would like to add a vector of datetimes to the first column. The first row of the matrix is frequency values, the first column would be datetimes, and the cells filled with decibel values. However, since the first row of the datetime vector is NaT, I get an error when I try to append it. How could I overcome this? Thanks!
I tried:
A=cat(2,t,output_plot);
%where t is datetime vector and output_plot is the double matrix

回答 (1 件)

Eric Sofen
Eric Sofen 2020 年 6 月 9 日
The NaT isn't the problem. You cannot concatenate datetime and double in a homogenous matrix:
>> x = [1 2 datetime('now')]
Error using datetime/horzcat (line 1387)
All inputs must be datetimes or date/time character vectors or date/time strings.
Either store the data in a table/timetable, which is intended to store variables of different types but the same height, or decide how you want to convert the datetime into something that can be represented as a double (i.e. if all you needed was hour-of-the-day, you could extract that), although that loses the datetime functionality.

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by