Can we change legend value without re-run the whole code?

조회 수: 1 (최근 30일)
SANDEEP SINGH RANA
SANDEEP SINGH RANA 2021년 8월 19일
답변: Walter Roberson 2021년 8월 19일
Hi,
Can I change the legend value without re-run the whole code as running whole code will take around 12 hours?
By mistake in the legend, I have written " user-1 , user-1" instead of " user-1, user-2".
How can I modified the plot? I did find any field to modify this.
Please help.

채택된 답변

Walter Roberson
Walter Roberson 2021년 8월 19일
L = findobj(gcf, 'type', 'legend');
L.String{4} = 'user-2'; %to change the 4th legend
if you have multiple legends in the figure, you will have to select the correct entry in L.
I used gcf instead of gca because you might well not happen to have the correct axes as the "current" one.
If you are using App Designer then the gcf will probably not work, and you might need groot instead of gcf and you might possibly need findall instead of findobj

추가 답변 (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