Hello, I am trying to plot an animated figure, where two points move. I need this to be done in a single MATLAB figure. Usually, this is done in a for loop, but this creates multiple figures and, for various reasons, I would prefer to avoid this. I would like to first declare a figure, appropriately prepare it (axes, grid, box, and so on) and then simply draw on it. The hold function doesn't create multiple figures, but it will leave "tails" (previous positions of the moving points). This is a simple working example (single point) of what I am trying to do (but it will leave tails).
P.S. I am aware of the comet function, but it leaves a tail.
x = (1:0.01:2*pi)';
y = sin(x);
figure;
hold on;
plot(x(1),y(1),'db');
axis([min(x) max(x) min(y) max(y)]);
xlabel('X', 'Interpreter','Latex');
ylabel('Y', 'Interpreter','Latex');
grid on;
box on;
for k = 2:length(x)
plot(x(k),y(k),'db');
drawnow
end
hold off;
2 Comments
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/551197-single-figure-animation-of-moving-points-without-tails#comment_904987
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/551197-single-figure-animation-of-moving-points-without-tails#comment_904987
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/551197-single-figure-animation-of-moving-points-without-tails#comment_910144
Direct link to this comment
https://es.mathworks.com/matlabcentral/answers/551197-single-figure-animation-of-moving-points-without-tails#comment_910144
Sign in to comment.