Problem with figure legend in loop for selecting multiple columns
Afficher commentaires plus anciens
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 70x70 matrices. (So, for the matrix format, it becomes a 70x420 matrix)
Here the code works with the legend (where x and y are a 70x70 matrix)
N=6;
figure
hold on
clr = jet(N);
for j=1:N;
plot(x(1:end,j), y(1:end,j), 'Color',clr(j,:))
end
hold off
str = 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 70x70 matrix in the x and y matrix, the legend colors become corrupt and display 4 blues and 2 cyan:
N=6;
figure
hold on
clr = jet(N);
for j=1:N;
plot(x(1:end,j:j+1), y(1:end,j:j+1), 'Color',clr(j,:))
end
hold off
str = 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?
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Legend dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!