I need help animating the evolution of a polar plot and saving it as a gif.

4 vues (au cours des 30 derniers jours)
Robin Seibel
Robin Seibel le 20 Mai 2023
Réponse apportée : DGM le 20 Mai 2023
I'm trying to animate a polar plot for a student. The plot is r=theta^2 on the interval [-2pi,2pi]. This what I have so far, and all I'm getting are empty graphs. Also, how can I fix the polar grid so that it's limits are constant?
clc
theta=linspace(-2*pi,2*pi,201);
rho=theta.^2;
figure;
grid on
filename='polarplot1.gif';
for i=1:length(theta)
polarplot(theta(i),rho(i),'-');
drawnow;
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif', 'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','WriteMode','append');
end
pause(0.025)
end

Réponses (1)

DGM
DGM le 20 Mai 2023
A few things:
You're only plotting one point at a time, so if you use a linestyle but no marker style, there's nothing to plot. Set a marker style if you want to plot a single point.
You need to capture the figure somehow. Nothing in your code appears to do that.
You'll probably want to set the GIF frame delay.
theta=linspace(-2*pi,2*pi,201);
rho=theta.^2;
delay = 0.1; % set the frame delay
figure;
grid on
filename='polarplot1.gif';
for i=1:length(theta)
polarplot(theta(i),rho(i),'o'); % use a marker style
drawnow;
im = frame2im(getframe(gcf)); % capture the frame
[imind,cm] = rgb2ind(im,256);
if i == 1
imwrite(imind,cm,filename,'gif','delaytime',delay,'Loopcount',inf);
else
imwrite(imind,cm,filename,'gif','delaytime',delay,'WriteMode','append');
end
%pause(0.025)
end
You also might want to set the axes limits to some fixed value so that it's not constantly changing.

Catégories

En savoir plus sur Polar Plots dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by