timetable 2 table error

31 次查看(过去 30 天)
Sarah Yun
Sarah Yun 2019-12-28
回答: dpb 2019-12-28
Hello,
I want to convert a timetable to an array for display on plot
N = timetable2table(A 'ConvertRowTimes',true);
N = table2array(N);
ERROR: Unable to concatenate the specified table variables.
Caused by:
Error using datetime/horzcat (line 1334)
All inputs must be datetimes or date/time character vectors or date/time strings.
I think the problem is the first date column? This is what it looks like.
sdfsdfsgd.jpg
Please can you help? Thank you.

采纳的回答

dpb
dpb 2019-12-28
Don't need to convert, plot() is overloaded to be datetime aware. Just use the t-table time variable (presuming that's what you want to plot other variable(s) against) as the X and the selected others as the y argument(s).
Example concocted from the documentation example for illustration:
Date = datetime({'2015-12-18';'2015-12-18';'2015-12-18'});
StormDuration = [hours(1);hours(2);hours(12)];
Temp = [37.3;39.1;42.3];
Pressure = [29.4;29.6;30.0];
Precip = [0.1;0.9;0.0];
TT = timetable(Temp,Pressure,Precip,StormDuration,'RowTimes',Date+StormDuration);
>> TT % show what got...
TT =
3×4 timetable
Time Temp Pressure Precip StormDuration
____________________ ____ ________ ______ _____________
18-Dec-2015 01:00:00 37.3 29.4 0.1 1 hr
18-Dec-2015 02:00:00 39.1 29.6 0.9 2 hr
18-Dec-2015 12:00:00 42.3 30 0 12 hr
>>
% now plot the temperature variable
plot(TT.Time.StormDuration,TT.Temp,'*-')
hold on % get ready to add to plot
plot(TT.Time,TT.Precip,'x-')
As long as same variable type, can concatenate and plot them together as well...
figure % new figure
plot(TT.Time,[TT.Temp TT.Pressure TT.Precip],'*-')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dates and Time 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by