MATLAB: How to make animtion of 3D surface plot

MATLAB

I'm having my code here where I want to put animation. Can we show this animation wrt to any parameter?

Best Answer

See this example using variable 't'. Adapt it according to your requirement
%suface plot;
x=-20:1:20;
y=-20:1:20;
[x,y]=meshgrid(x,y);
c1=0.1576;
A1=0.9706;
A2=0.9572;
A3=0.4854;
A4=2*A3;
T = linspace(0, 1, 100);
fig = figure;
ax = axes();
hold(ax);
view(3);
grid on
colormap jet;
xlabel('\bf{x}','fontsize',18);
ylabel('\bf{y}','fontsize',18);
zlabel('\bf{u (x,y,t)}','fontsize',18);
s = surf(x,y,zeros(size(x)),'Facealpha','1'); % temporary surface to get the handle
v = VideoWriter('test.mp4', 'MPEG-4');
open(v);
for i=1:numel(T)
t=T(i);
b=cos(t);
A=log(b);
s.ZData = c1./((x./(A1+3*t).^1./3+A-(A2+y)./(A1+3*t).^1./3-A4)*(A1+3*t).^1./3);
drawnow;
frame = getframe(fig);
writeVideo(v, frame)
end
close(v);