필터 지우기
필터 지우기

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

조회 수: 5 (최근 30일)
Robin Seibel
Robin Seibel 2023년 5월 20일
답변: DGM 2023년 5월 20일
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

답변 (1개)

DGM
DGM 2023년 5월 20일
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.

카테고리

Help CenterFile Exchange에서 Polar Plots에 대해 자세히 알아보기

제품


릴리스

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by