Live Script: Multiple Figures Merge into a Single Animation
19 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
When running a Live Script that plots several figures inside a loop, I expect MATLAB to produce separate animations, one per figure.
However, all plots are combined into a single inline animation — the frames from different figures appear alternately, making the animation look like a “blinking” mix of results.
Here’s a simplified version of my code:
a = linspace(0, pi ,100);
for ii = 1:100
figure(1); hold on; box on
plot(gca, a(ii), sin(a(ii)), 'r*')
xlim([0 pi]); ylim([-1 1]);
drawnow
figure(2); hold on; box on
plot(gca, a(ii), cos(a(ii)), 'r*')
xlim([0 pi]); ylim([-1 1]);
drawnow
end
In the Live Editor, instead of getting two separate animations (one for figure(1) and one for figure(2)), the frames from both are merged into one.
Any guidance or best practices for managing multiple animated figures in Live Scripts would be appreciated.
0 commentaires
Réponses (1)
Dyuman Joshi
le 14 Oct 2025 à 14:59
%Data
N = 500;
x = linspace(0, pi, N);
y1 = sin(x);
y2 = cos(x);
%Generate subplot
sub = subplot(2,1,1);
axis([0,2*pi,-1,1])
h1=animatedline('Color','r');
subplot(2,1,2)
axis([0,2*pi,-1,1])
h2=animatedline('Color','k');
%Plot lines point by point
for k=1:N
addpoints(h1,x(k),y1(k));
addpoints(h2,x(k),y2(k));
drawnow
end
1 commentaire
Voir également
Catégories
En savoir plus sur Animation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!