MATLAB: How to draw animatedlines in a ‘polarplot’?

animatedlinespolarplot

Here is my code, I wanna to draw a cosine animatedline in polar coordinates rather than cartesian coordinates, what can I do? XD
N = 10000;
phi = linspace(0, 2 * pi, N);
u1 = 3;
figure
grid on
h = animatedline;
M = 1e3;
varphic = linspace(0, 2 * pi, M);
for i = 1 : M
z = cos(u1 .* phi + varphic(1, i));
clearpoints(h);
addpoints(h, phi, z);
drawnow update
end

Best Answer

I never attempted to use animatedline with polarplot.
See if this does what you want:
N = 10000;
phi = linspace(0, 2 * pi, N);
u1 = 3;
figure
grid on
h = animatedline;
M = 1e3;
varphic = linspace(0, 2 * pi, M);
for i = 1 : M
z = cos(u1 .* phi + varphic(1, i));
h = polarplot(phi,z);
% clearpoints(h);
% addpoints(h, phi, z);
drawnow update
end
Of interest, clearpoints and addpoints are scripts, not functions.