Refresh plot for animation

4 ビュー (過去 30 日間)
Søren Holm-Petersen
Søren Holm-Petersen 2018 年 2 月 15 日
コメント済み: Adhavan Kadhiravan 2019 年 7 月 20 日
Hello
I would like to animate a pendulum rod with a mass attached through a spring. My question is about animation. Currently I am plotting the mass as a circle, and the rod as a line from origo to the endpoint. I use hold on, but this means I get every line in my animation. But If I do not use hold on it only plots the line and not the mass.
So how do I get a fresh image for every iteration of my loop?
Thanks in advance.
for N = 2:1000
hold on
axis([-2*L1 2*L1 -2*L1 2*L1]);
plot(bob_pos(1,N),bob_pos(2,N),'o', 'MarkerFaceColor', 'red'); %Plots the moving mass as circle
plot([0 pend_end_pos(1,N)], [0 pend_end_pos(2,N)], '-'); %Plots pendulum rod as line from origo to endpoint
pause(0.025);
end

採用された回答

Walter Roberson
Walter Roberson 2018 年 2 月 16 日
Use the order
plot 1
hold on
plot 2
axis
hold off
drawnow()
... There are better ways than this but I am not at my desk at the moment
  2 件のコメント
Søren Holm-Petersen
Søren Holm-Petersen 2018 年 2 月 16 日
Thanks, worked like a charm.
Adhavan Kadhiravan
Adhavan Kadhiravan 2019 年 7 月 20 日
Thanks a lot

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by