Holding legend with multiple plots

조회 수: 3 (최근 30일)
ma sd
ma sd 2020년 6월 14일
댓글: Walter Roberson 2020년 6월 22일
I am using app designer and I have a plot that takes input from the interface then plots it. each time I am plotting, I'm holding the uiaxis on to keep previous plots. however I am not able to get the legend to update and maintain previous components. is it possible to do it?
  댓글 수: 2
Ajay Kumar
Ajay Kumar 2020년 6월 14일
why dont you write legend command after plotting all the plots?
ma sd
ma sd 2020년 6월 16일
it's not predetermined I am exploring multiple variations of weights for my model then plotting them in the app

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

답변 (2개)

Suhas Maddi
Suhas Maddi 2020년 6월 18일
Hii,
I think You are trying to store the legend values for each iteration and add new values to that legend.
There are two ways to do so :
  1. Use a cell array of character vectors or string array or categorical array and append your new legend values to this cell array and plot the legend for every iteration.
  2. You can use legappend function as mentioned here: https://blogs.mathworks.com/pick/2014/07/25/append-entries-to-a-legend/
Hope this helps you.
  댓글 수: 2
ma sd
ma sd 2020년 6월 21일
how would you go about creating the array and appending it to include new plots?
legappend didn't work for me as matlab didn't recognize it
Walter Roberson
Walter Roberson 2020년 6월 22일
You would need to install legappend from https://www.mathworks.com/matlabcentral/fileexchange/47228-legappend or from the Add-On Explorer.

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


Suhas Maddi
Suhas Maddi 2020년 6월 22일
Hii ma sd,You can do something like this :
>>X=1:10;
>>Y=5:5:50;
>>Z=10:10:100;
>>labels={};
>>plot(X,Y);
>>labels{end+1}='label1';
>>legend(labels);
>>hold on
>>plot(X,Z);
>>labels{end+1}='label2';
>>legend(labels);
>>hold off
I am attaching the results too.
I hope this helps you.

카테고리

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

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by