MATLAB: Trouble with 3D surface Plotting.

3d plotssurface plots

How can I set the z axis for this plot? It changes with every iteration regardless of what the axis function tells it to do.
clear all
clear
clc
x = linspace(0,2,30); %x data points
y = linspace(0,3,20); %y data points
[xgrid,ygrid] = meshgrid(x,y); %create grid of all x and y points
m=1;
n=1;
figure(3)
axis square
box on
grid on
t= linspace(0,5,50);
for k = 1:50
axis([0 2 0 3 -5 5])
animate = (576/(pi^6)).*((((1+((-1).^(m+1))).*(1+((-1).^(n+1))))/(m.^3.*n.^3)).*sin((m.*pi.*xgrid)/2).*sin((m.*pi.*ygrid)/3).*cos(pi.*t(k).*(sqrt(9.*(m.^2)+4.*(n.^2)))));
surf(xgrid,ygrid,animate);
pause(0.01);
colormap jet
box on
axis([0 2 0 3 -5 5])
end

Best Answer

You limit the z-axes to certain limit. Imagine what would be the maximum and minimum limits of z and then limit it.
add:
zlim([-3 3])
after surf in your code, now z is limited to 3 and -3. It will not change.
Related Question