필터 지우기
필터 지우기

Legend for plot genereted by a loop

조회 수: 1 (최근 30일)
Kelly Kyriakou
Kelly Kyriakou 2015년 10월 8일
댓글: Kelly Kyriakou 2015년 10월 10일
I want to plot 2 variables and each row of the 2 variables to be presented with different color. So I wrote the following code which plot through loop:
plot(Xindex2plot,Yindex2plot,'color',cc(allSS,:));
However, I have problem with the legend. At legend it is presented only the color of the last row of data and the text respectively. This is the code for the lgend which it is supposed that produced through loop also.
% s{allSS}=sprintf('%s',nameofsource2open);
% legend(plotall,s)
How I should reform it to present all the data and the texts?
Thank you in advnace

채택된 답변

Thorsten
Thorsten 2015년 10월 8일
Store a handle to each plot in h(i) and let the legend refer to this handle h:
col = rand(3, 3);
data = rand(3, 100);
axis, hold on, for i=1:3, h(i) = plot(data(i,:), 'Color', col(i,:)); end
legend(h, {'data1' 'data2' 'data3'})
  댓글 수: 4
Kelly Kyriakou
Kelly Kyriakou 2015년 10월 8일
Thank you very much!!!
Kelly Kyriakou
Kelly Kyriakou 2015년 10월 10일
It works!!! Thank you very much

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Legend에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by