Animation delete previous point
73 ビュー (過去 30 日間)
古いコメントを表示
Hi
I'm trying to make an animation, where I only display one point at the time, right now the trajectory stays, and I want only one point displayed
any suggestions, i want it to look like this: https://www.youtube.com/watch?v=q1dqIcLi3N0
this is my code so far
x= Ball(:,1);
y= Ball(:,2);
%%
figure
curve = animatedline('marker','*','Color','r');
set(gca,'Xlim',[-6000 6000], 'Ylim',[-4000 4000])
for i= 1:length(Ball)
addpoints(curve,x(i),y(i));
drawnow
end
0 件のコメント
採用された回答
Adam Danz
2019 年 2 月 28 日
編集済み: Adam Danz
2019 年 2 月 28 日
If your task is that simple, I prefer updating the XData and YData rather than using the animatedline method. This is faster and more efficient. Instead of deleting and drawing a new point on each iteration, it merely changes the coordinate value of the point that is already drawn. If this is too fast, you can control the approximate timing by using pause() within the loop to slow it down.
Here's an example (just run this to watch a dot move along a sinusoidal trajectory).
x= 0:0.1:2*pi;
y= sin(x);
figure
ph = plot(x(1), y(1), 'r*'); %plot initial point
set(gca,'Xlim',[0 6.5], 'Ylim',[-1 1])
for i=1:length(y)
ph.XData = x(i); %change x coordinate of the point
ph.YData = y(i); %change y coordinate of the point
drawnow
pause(0.05) %control speed, if desired
end
If you prefer to use the animatedline method, just insert clearpoints() before you call addpoints().
for i= 1:length(Ball)
clearpoints(curve)
addpoints(curve,x(i),y(i));
drawnow
end
2 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Animation についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!