简体   繁体   中英

MATLAB: plot timetable matrix

I would like to plot all columns of a timetable. For example, let's say, I have a timetable with two columns.

time = datetime({'2017-11-15'; '2017-11-18'; '2017-11-19'});
col1 = [NaN;4;5];
col2 = [7;6;4];
tt = timetable(time, col1, col2);

How can I plot all columns (line chart)?

Let me add three things:

  1. I don't know the column titles in advance.
  2. I don't know the number of columns in advance.
  3. The first columns might not necessarily be the longest column (see NaN).

There's an even less complicated version. :-)

plot(tt.time, tt.Variables);

Take a look at varfun :

>> ax = axes('NextPlot','add');
>> varfun(@(v) plot(ax,tt.time, v), tt)

从 R2018b 版本开始, stackedplot函数使这变得更加容易,这是stackedplot

stackedplot(tt)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM