Borrar filtros
Borrar filtros

Plotting continuous motion using loops

8 visualizaciones (últimos 30 días)
Faith
Faith el 3 de Mzo. de 2023
Comentada: Faith el 3 de Mzo. de 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

Respuesta aceptada

Morgan
Morgan el 3 de Mzo. de 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

Más respuestas (0)

Categorías

Más información sobre Animation en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by