timetable 2 table error

59 visualizaciones (últimos 30 días)
Sarah Yun
Sarah Yun el 28 de Dic. de 2019
Respondida: dpb el 28 de Dic. de 2019
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.

Respuesta aceptada

dpb
dpb el 28 de Dic. de 2019
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],'*-')

Más respuestas (0)

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by