animate 2d plot
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Hi, All!
Say i have 2 variable, x1 and x2. I wanna plot (x1, x2) and animate it over time. i've tried this code:
x = [1 2;2 1;3 1;1 2;2 1;3 2];
x1 = x(1:end,1);
x2 = x(1:end,2);
r=animatedline;
for t=1:1000
for i=1:6
x1(i,t+1)=x1(i,t)+3;
x2(i,t+1)=x2(i,t)+x1(i,t);
end
addpoints(r,x1(1,:),x2(1,:))
addpoints(r,x1(2,:),x2(2,:))
drawnow
end
But that's not what i meant. From code above, the first line move from (1,2) to (4,3) to (7,7).... the second line move from (2,1) to (5,3), to (8,8),...
till the figure show the movement of those 6 lines.
4 Commenti
Risposte (1)
Cris LaPierre
il 3 Ago 2020
Modificato: Cris LaPierre
il 3 Ago 2020
Here's one way to do it following the instructions on the Line Animations documentation page. I reduced the number of points to 100.
x = [1 2 3 1 2 3];
y = [2 1 1 2 1 2];
l1 = animatedline;
l2 = animatedline;
l3 = animatedline;
l4 = animatedline;
l5 = animatedline;
l6 = animatedline;
axis([0 150 0 1500])
for t = 1:100
if t>1
x(t,:)=x(t-1,:)+3;
y(t,:)=y(t-1,:)+x(t,:);
end
addpoints(l1,x(t,1),y(t,1))
addpoints(l2,x(t,2),y(t,2))
addpoints(l3,x(t,3),y(t,3))
addpoints(l4,x(t,4),y(t,4))
addpoints(l5,x(t,5),y(t,5))
addpoints(l6,x(t,6),y(t,6))
drawnow limitrate
end
0 Commenti
Vedere anche
Categorie
Scopri di più su Animation in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!