Problem with figure legend in loop for selecting multiple columns
이전 댓글 표시
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?
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!