Plotting continuous motion using loops

14 ビュー (過去 30 日間)
Faith
Faith 2023 年 3 月 3 日
コメント済み: Faith 2023 年 3 月 3 日
Hello, so I have code up and running that animates a few graphical objects for a theta = -65 : 0. I now want to do this same thing but keep the animation running back and forth between 0 and -65 and back again. Is there a way to do this with loops?
Currently my set up is similar to:
theta = linspace(-65,0);
i = length(theta);
while(i>0)
y=sind(theta);
y_plot = y*sind(theta(i));
plot(theta,y_plot)
i = i-1;
pause(0.1);
end

採用された回答

Morgan
Morgan 2023 年 3 月 3 日
Try something along these lines:
% CREATE ANGLE ARRAY
theta = linspace(-65,0);
i = length(theta);
% LOOP FORWARD THEN BACKWARD
for n = [ 1:i i-1:-1:2 ]
% Plot Stuff Here
end
If you're trying to create a loopable animation, this is the code to do it without duplicate frames that will look choppy. This way, it will be a smooth transition from forward to backward animation.
Let me know if you have questions or need any more help!
  • Morgan Blankenship, MS, EIT
  1 件のコメント
Faith
Faith 2023 年 3 月 3 日
This is awesome, thank you!

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

その他の回答 (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