Filter löschen
Filter löschen

Plotting continuous motion using loops

8 Ansichten (letzte 30 Tage)
Faith
Faith am 3 Mär. 2023
Kommentiert: Faith am 3 Mär. 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

Akzeptierte Antwort

Morgan
Morgan am 3 Mär. 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

Weitere Antworten (0)

Kategorien

Mehr zu Animation finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by