Update legend to current plot
조회 수: 2 (최근 30일)
이전 댓글 표시
I'm writing a code where I have one constant dataset that stays in the plot the entire time while the other datasets pop up in the plot one by one.(I'm deleting the pop-up dataset-plot after every iteration; which means that I at every time only have two plots in my figure - the constant dataset and the current pop-up dataset). As far as I know you can't have multiple legends in a matlab plot, so I want to make a legend for the pop-up datasets that updates after every iteration (i.e legend changing color in accordance to plot). To delete the plots i'm simply using the delete(plot) command however I haven't figured out if you can do anything similar with legends
댓글 수: 0
답변 (1개)
KSSV
2016년 3월 1일
% constant plot
t = linspace(0,2*pi) ;
x = 0.5*sin(t) ;
for i = 1:100
plot(t,x,'r') ; % plot constant sine function
hold on
% Generating a random varying second function
dx = 0.1*randn(size(t)) ;
x2 = x+dx ; % A varying function
plot(t,x2,'color',rand(1,3)) ; % plot second varying function
hold off
legend('sin function','varying function')
drawnow
end
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Legend에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!