Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

I have problems with multi legends

조회 수: 2 (최근 30일)
Korhan Cengiz
Korhan Cengiz 2015년 11월 11일
마감: MATLAB Answer Bot 2021년 8월 20일
Can you give some idea for my problem like this:
for plot legend end
then
if (main)
if 1
plot
legend
if 2
plot
legend
...
if n
plot
legend
end
end
for each legend I want to renew the legend box and I want to add it to box and I want to update and enlarge the box.
Thanks

답변 (1개)

dpb
dpb 2015년 11월 11일
편집: dpb 2015년 11월 11일
First, save the handle to the legend on creation. Then, also save the line handles created by plot each time in an array and augment the handle 'String' property associating the the cell array of titles with the line plot handles...
hL=zeros(N,1); % for line handles
hL(1)=plot(...; % first line
lab{1,1}=num2str(1,'Line %2d'); % first label
hLg=legend(lab); % create the legend object, first label
hold on % to add onto existing...
for i=2:N % subsequent after first preparation
hL(i)=plot(...; % next line
lab{i,1}=num2str(i,'Line %2d'); % and next label add to cell array
legend(hL,lab); % apply the current labels to the existing line handles..
end
Alternatively, of course, you can build the array of data as a 2D array and wait and plot all in "one swell foop" and then legend can automagically do the association of an array of labels one:one with the lines (columns) in the array. But, the above is the pattern to do it a line at a time which has its reasons for doing so, granted...
  댓글 수: 2
Korhan Cengiz
Korhan Cengiz 2015년 11월 11일
thanks your reply but can you send me example with usage of if clauses.
dpb
dpb 2015년 11월 11일
What about if? There are examples at
doc if
The issue you outlined above re: adding to a legend has to do with keeping track of the handles of the objects in the axes to be added to an existing legend, not if...that appears a distraction.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by