Little Bobby Tables
Little Bobby Tables

Reputation: 4744

Format each line in plot(x,y) where x is a matrix

I wish to format each line in a plot so that I can choose given colours for each line. However my x values are in matrix form so I cannot use the plot(x,y,'b',x,y,'r',...) style format. Many thanks.

Upvotes: 0

Views: 36

Answers (2)

Emilien
Emilien

Reputation: 2445

If you don't need to choose colors as long as they are different, you can plot(transpose(data)) which will plot every line of data with a different color.

Upvotes: 0

Ander Biguri
Ander Biguri

Reputation: 35525

I would recommend doing in a for loop, but maybe there is another way of doing it.

Define your colors in a matrix

cmap = hsv(10) %generate 10 random colors
hold on
for ii=1:10
   plot(x(ii,:),y(ii,:),'color',cmap(ii,:))
end

Create cmap, as you wish. It needs to be a nlines X 3 size though.

Upvotes: 1

Related Questions