# A moving point plot in MATLAB figure with animation.

751 views (last 30 days)
Aakash on 24 Jul 2013
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.
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Accepted Answer

Iman Ansari on 24 Jul 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
##### 1 CommentShowHide None
SARA on 20 Dec 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

Sign in to comment.

### More Answers (2)

Image Analyst on 24 Jul 2013
Use the comet() function. It does exactly that.
##### 4 CommentsShowHide 3 older comments
Image Analyst on 7 Oct 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

Sign in to comment.

Mohamadreza Khashei on 3 Nov 2021
for k = 1 : whatever x = ...... y = ...... plot(x, y, 'r.', 'MarkerSize', 30); end
##### 0 CommentsShowHide -1 older comments

Sign in to comment.

### Community Treasure Hunt

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

Start Hunting!

Translated by