0
votes

I have a three column matrix [year, month, data] and I'm trying to make a plot that compares monthly trends in the data across years. I've tried to do this using plot3, mesh, and ribbon.

Plot3(year, month, data) gets me pretty close to what I need, but the data is all connected even when it jumps from one year to the next, so what I get looks a lot like scribbling instead of one nice line for each year.

I thought using mesh or ribbon might fix this, but I'm stuck because the format for mesh is (X,Y,Z) where Z is a matrix, and if I treat my three columns separately, I'm left with only a vector for Z.

Any help is greatly appreciated!

1

1 Answers

0
votes

You need to reformat your matrix [year month data] to use mesh or ribbon. For example, if your original matrix is like this:

[year month data]
 2001  1   100
 2001  2   101
 2001  3   102
 2002  1   104
 2002  2   105
 2002  3   106

Then you plot like this:

year=[2001,2002];
month=[1,2,3];
data=[100,104;101,105;102,106];
mesh(year,month,data);
% if it doesn't work, replace the last line with follow
% mesh(year,month,data');