A moving point plot in MATLAB figure with animation.

213 visualizzazioni (ultimi 30 giorni)
My program calculates position of a point on Z plane as (X,Y). I need to plot (X,Y) in Z-plane with a moving point showing location of point over the time in a single MATLAB figure. Please help.

Risposta accettata

Iman Ansari
Iman Ansari il 24 Lug 2013
n = 50;
XY = 10 * rand(2,n) - 5;
for i=1:n
plot(XY(1,i),XY(2,i),'or','MarkerSize',5,'MarkerFaceColor','r')
axis([-5 5 -5 5])
pause(.1)
end
  2 Commenti
Usama Faisal
Usama Faisal il 20 Dic 2020
i=1;
for n=1:length(y) % use for loop to animate the line
if y(n)>sur(n)
plot(x(n),y(n),'o','MarkerFaceColor','b')
i=i+1;
grid on
drawnow
else
end
end
Bodie
Bodie il 24 Apr 2024 alle 13:10
what does sur stand for?

Accedi per commentare.

Più risposte (3)

Image Analyst
Image Analyst il 24 Lug 2013
Use the comet() function. It does exactly that.
  4 Commenti
reema shrestha
reema shrestha il 7 Ott 2017
Modificato: reema shrestha il 7 Ott 2017
I exactly want to do the same thing in projectile motion simulation. Instead of using comet to trace the path as well,I want to create a ball and make it follow the trajectory without drawing the trajectory,just the ball moving. Can you suggest me any?
Image Analyst
Image Analyst il 7 Ott 2017
You can perhaps just use plot() with a big dot marker over and over:
for k = 1 : whatever
x = ......
y = ......
plot(x, y, 'r.', 'MarkerSize', 30);
end

Accedi per commentare.


Mohamadreza Khashei
Mohamadreza Khashei il 3 Nov 2021
for k = 1 : whatever x = ...... y = ...... plot(x, y, 'r.', 'MarkerSize', 30); end

Muhammad Hadyan Utoro
Muhammad Hadyan Utoro il 29 Set 2022
Spostato: Image Analyst il 29 Set 2022
x = [0:0.01:2*pi];
for i = 1:length(x)
y = sin(x);
figure(1)
plot(x,y,'-o','MarkerIndices',1+i)
hold off
pause(0.005)
end

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!

Translated by