Take the 2-minute tour ×

Is there a way to specify the colors of the lines when plotting the matrix.

For instance:

// here is my matrix A
A = [13, 3, 4;19, 0, 1;18, 0, 2;19, 0, 1;19, 0, 1]; 
// when I am plotting it I am not in control of what color each line will be


plot(A, 'r')

just colors everything in red (which is expected) When trying something like

plot(A, ['r', 'g','b'])


plot(A, 'rgb')

does not work (which is not surprising)

So is there any way to specify color for each line?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

You can change the color afterwards:

A = [13 3 4;
     19 0 1;
     18 0 2;
     19 0 1;
     19 0 1];


clrs = jet(numel(p)); % just a Nx3 array of RGB values
for ii=1:numel(p)


% same thing as above

enter image description here

share|improve this answer
wow, this looks amazing. Thanks, I will check this tomorrow when will come back to my windows machine and accept it –  Salvador Dali Dec 7 '12 at 0:59
add comment

The plot function doesn't provide a way to do it as concisely as in your example. Instead, you can try:

plot(A(:, 1), 'r', A(:, 2), 'g', A(:, 3), 'b');
share|improve this answer
Thanks, I tried it, the problem here is that my matrix is a little bit bigger (like 30x30) and it might be annoying to do all this A(:,i) –  Salvador Dali Dec 6 '12 at 23:35
add comment

Your Answer


