MATLAB: Timetable 2 table error


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.
Please can you help? Thank you.

Best Answer

  • 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
    hold on % get ready to add to plot
    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],'*-')