I am having difficulty with my legend displaying the correct colors for a loop plotting figure.
To trouble shoot, I have tried matrices and cell formats for my x and y variables. Both x and y contain 6 sets of 70×70 matrices. (So, for the matrix format, it becomes a 70×420 matrix)
Here the code works with the legend (where x and y are a 70×70 matrix)
N=6; figurehold onclr = jet(N); for j=1:N; plot(x(1:end,j), y(1:end,j), 'Color',clr(j,:))end hold offstr = cellstr( num2str((1:N)','Run%d') );%
legend(str)
This creates a figure that displays different colors on the legend corresponding to the plot colors correctly
However, when I try to select various sets of columns in my 70×70 matrix in the x and y matrix, the legend colors become corrupt and display 4 blues and 2 cyan:
N=6;figurehold onclr = jet(N); for j=1:N; plot(x(1:end,j:j+1), y(1:end,j:j+1), 'Color',clr(j,:))endhold offstr = cellstr( num2str((1:N)','Run%d') );%legend(str)
Does anyone know how to fix the second image to correlate plot and legend colors? Why is it only when I try to select various columns?
Best Answer