Azzera filtri
Azzera filtri

Plotting continuous motion using loops

8 visualizzazioni (ultimi 30 giorni)
Faith
Faith il 3 Mar 2023
Commentato: Faith il 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

Risposta accettata

Morgan
Morgan il 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

Più risposte (0)

Categorie

Scopri di più su Animation in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by