Animation of a unit circle arrow sweeping from 0 to 2*pi
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Nilay Modi
el 22 de Jun. de 2024
Respondida: Nilay Modi
el 22 de Jun. de 2024
Just doing basic animation of an arrow in a unit circle sweeping from 0 to 2*pi using the Matlab provided animation sample code of playing a movie using the movie function.
I took the sample code from Matlab, commented the parts that were related to the peaks animation and replaced them with the unit circle animation that I am trying to do.
The animation is happening, but the scale is getting bigger an bigger with each frame...making the unit arrow appearing smaller.
Why is this happening? Thanks.
Record Frames and Play Movie Once
Use the getframe function in a loop to record frames of the peaks example function, then play the movie frames once.
Create a figure object h. Initialize the surface plot of the peaks function Z. Customize the figure axes.
h = figure;
% Z = peaks;
% surf(Z)
theta = linspace(0, 2*pi, 40);
r = ones(1,length(theta));
[u, v] = pol2cart(theta, r);
axis tight manual
ax = gca;
ax.NextPlot = 'replaceChildren';
Preallocate a 40-element array M to store the movie frames.
loops = 40;
M(loops) = struct('cdata',[],'colormap',[]);
For each iteration of j, capture each plot of function X as an individual frame. Store the frame in M.
Set the 'Visible' property of the figure object to 'off' to hide the surface plots while calculating X.
h.Visible = 'off';
for j = 1:loops
% X = sin(j*pi/10)*Z;
% surf(X,Z)
compass(u(j),v(j))
drawnow
M(j) = getframe;
end
Set the 'Visible' property of the figure to 'on' and play the movie in M once.
h.Visible = 'on';
movie(M);
0 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Animation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!