MATLAB: How to animate tangent function

animation

Hello,
I don't know how to animate tangent function, so that it shows from -2*pi to 2*pi.
If you have any ideas, please help.
Here is my code:
clear;
clc;
close all;
%f=@(theta) tan(theta); %This part draws it nicely but I don't know how to animate it
%figure
%fplot(f,[-2*pi,2*pi])
x = (-pi/2)+0.01:0.01:(pi/2)-0.01; %This part animates it but it doesn't look as nice as the one above
y=tan(x);
plot(x,y), shg
comet(x,y)

Best Answer

Try this
clear;
clc;
close all;
x = (-2*pi):0.01:(2*pi); %This part animates it but it doesn't look as nice as the one above
y=tan(x);
figure();
ax = axes();
hold(ax);
xlim([-2*pi 2*pi])
ylim([-8 8]);
comet(x,y)