How to change color of vectors when plot a matrix?

I have plot(Y) where Y is a matrix
How do I change resulted color and line pattern for each vector inside Y? Many thanks!

Answers (3)

See my colororder demo, attached. You can make the lines be any color you want by changing the "ColorOrder".
See the documentation for plot, specifically Specify Line Style, Color, and Marker.

2 Comments

It only works to change the color for the entire matrix. I need to change color for each vector in Y (say Y is a N*3 matrix). Any ideas?
See the Axes Properties documentation on Line Colors and Line Styles.

Sign in to comment.

Set the axes colororder property (here the colormap is winter, but you can choose the colormap to suit):
N = 6;
axes('ColorOrder',winter(N),'NextPlot','replacechildren')
X = linspace(0,pi*3,1000);
Y = bsxfun(@(x,n)n*sin(x+2*n*pi/N), X.', 1:N);
plot(Y)

Categories

Tags

Asked:

my
on 27 Sep 2015

Answered:

on 27 Sep 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!