1

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).
Andi
  • 3,196
  • 2
  • 24
  • 44

3 Answers3

3

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

plot(tt.time, tt.Variables);
Andi
  • 3,196
  • 2
  • 24
  • 44
  • Ah, yes indeed. Much nicer assuming that all of your columns are the same data type. If they are not, then this will either error or cast some datatypes into another, which might be undesirable. – Andy Campbell Nov 20 '17 at 17:32
1

Take a look at varfun:

>> ax = axes('NextPlot','add');
>> varfun(@(v) plot(ax,tt.time, v), tt)
Andy Campbell
  • 2,177
  • 13
  • 15
1

It's worth nothing that as of version R2018b, the stackedplot function makes this a lot easier:

stackedplot(tt)
sdeland
  • 56
  • 1