How do I plot N arrays at the same time as a animation?
Show older comments
I want to know the best way to animate several arrays into one plot, at the same time.
The example I'm working on is a closed box of balls, where I already have the arrays created. However the animation becomes very bad and choppy when there's more than one ball in animation, so I wanted to know if there's a better way of writing the code, or a more effiecent way to animate the arrays.
for i = 1:N_max
for j = 1:n
ball(j) = plot(x(j,i+1),y(j,i+1),'ok','MarkerFaceColor','k');
set(ball,'MarkerSize',diameter)
pause(1e-3)
if i~=N_max
reset(ball(j))
end
end
end
Answers (1)
Star Strider
on 3 Feb 2020
I am not certain what you want to do. There are several functions to produce animated plots in MATLAB. One such is drawnow, some related ones are refreshdata, and there are others.
Example —
[Xs,Ys,Zs] = sphere;
figure
for k1 = 1:0.03:3.2
Xp = Xs + cos(k1*2*pi);
Yp = Ys + sin(k1*2*pi);
surf(Xp, Yp, Zs)
axis equal
axis([-3 3 -3 3 -3 3])
text(-2.1, -1.8, 'Revolving Sphere')
% view(0,90)
grid on
refreshdata
drawnow update
end
hold off
This does not directly address the particle animation in your Question (since I cannot run your code), however it shows what is possible.
1 Comment
David
on 4 Feb 2020
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!