Effacer les filtres
Effacer les filtres

Plotting continuous motion using loops

8 vues (au cours des 30 derniers jours)
Faith
Faith le 3 Mar 2023
Commenté : Faith le 3 Mar 2023
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

Réponse acceptée

Morgan
Morgan le 3 Mar 2023
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 commentaire
Faith
Faith le 3 Mar 2023
This is awesome, thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Animation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by