timetable 2 table error

조회 수: 51 (최근 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에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by