Problem with adjusting axis limits in surface plot

Here's the code. I want to show only X values between 0 and 1. Y values between 0.001 and 1000, and adjust the Z automatically.
YS = @(X,Y) (0.38*X^2-0.31*X-0.02)*log(Y)+2.7287*sin(1.1732*X+1.1613);
%the coefficients are not constant numbers, this is just an example.
fsurf(Z);
xlim ([0 1]);
ylim ([0.001 1000]);
When I first plot the surface, this is how it looks like:
After I double click on the plot, it adjusts the Z automatically to this:
How do you get the second/correct view without interacting with the plot?

 Accepted Answer

Use zlim as well.
zlim([-3 3])

3 Comments

Thanks, but that wouldn't work. zlim is actually [-inf inf].
In this particular case, the upper limit is 3.2 and lower one is 1.6. The cofficients in the equation do change and that means the maximum and minimum values of Z also change. I want MATLAB to automatically adjust the zlim.
I would rather prefer:
x = linspace(0,1) ;
y = linspace(0,1000) ;
[X,Y] = meshgrid(x,y) ;
Z = (0.38*X.^2-0.31*X-0.02).*log(Y)+2.7287*sin(1.1732*X+1.1613);
%the coefficients are not constant numbers, this is just an example.
surf(X,Y,Z);
Thanks a lot. This works perfectly.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Asked:

on 9 May 2022

Commented:

on 9 May 2022

Community Treasure Hunt

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

Start Hunting!