Animation of a unit circle arrow sweeping from 0 to 2*pi

2 ビュー (過去 30 日間)
Nilay Modi
Nilay Modi 2024 年 6 月 22 日
回答済み: Nilay Modi 2024 年 6 月 22 日
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);

採用された回答

Nilay Modi
Nilay Modi 2024 年 6 月 22 日
I asked this question to the AI Chat Playground and got the answers!!!
In the for loop, I need to set the axis each time for each frame.
% outside the for loop
ax_2 = axes;
% inside the for loop
% Set the axes limits
ax2.RLim = [0 1]; % Set the radial limits
ax2.ThetaLim = [0 2*pi]; % Set the angular limits

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeAnimation についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by