Effacer les filtres
Effacer les filtres

Update legend to current plot

2 vues (au cours des 30 derniers jours)
kyrresc
kyrresc le 29 Fév 2016
Réponse apportée : KSSV le 1 Mar 2016
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

Réponses (1)

KSSV
KSSV le 1 Mar 2016
% 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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by