Previous legend replaces the new one in a plot, why?
조회 수: 11 (최근 30일)
이전 댓글 표시
In an app (desgined using Matlab), I plot x and y-data and clear axes using 'cla' in order to plot a different x-y data. The issue is- the legend from the previous re-appears on the new graph replacing the new legend. I can not understand why. I want to completely remove the legend for the first dataset and prepare the same axes for a new data. I have tried using other functions as well but it does not work. Any help would be appreciated. Thanks a lot.
댓글 수: 0
답변 (1개)
Kevin Holly
2022년 8월 19일
편집: Kevin Holly
2022년 8월 19일
Were you changing the location of the legend as shown below? I made a quick app (attached) using the approach below.
plot(rand(10,1),rand(10,1))
hold on
plot(rand(10,1),rand(10,1))
legend({'example';'example2'},"Location","west")
cla
plot(rand(10,1),rand(10,1))
If that is the case, you can create a handle for the legend and delete it after clearing axes.
figure
plot(rand(10,1),rand(10,1))
hold on
plot(rand(10,1),rand(10,1))
L=legend({'example';'example2'},"Location","west");
cla
delete(L)
plot(rand(10,1),rand(10,1))
legend
댓글 수: 2
참고 항목
카테고리
Help Center 및 File Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!