A moving point plot in MATLAB figure with animation.

221 次查看(过去 30 天)
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.

采纳的回答

Iman Ansari
Iman Ansari 2013-7-24
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 个评论
Usama Faisal
Usama Faisal 2020-12-20
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

请先登录,再进行评论。

更多回答(3 个)

Image Analyst
Image Analyst 2013-7-24
Use the comet() function. It does exactly that.
  4 个评论
reema shrestha
reema shrestha 2017-10-7
编辑:reema shrestha 2017-10-7
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 2017-10-7
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

请先登录,再进行评论。


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

Muhammad Hadyan Utoro
移动:Image Analyst 2022-9-29
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

类别

Help CenterFile Exchange 中查找有关 Animation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by