Jung
Jung

Reputation: 139

Limit output values shown within an interval

I dont know how to make Matlab show output value within an interval. I know how to fix range for input values (x,y) with linspace but not sure how to do the same thing for z. I have tried to define the range of z with function zlim but it doesn't work.

x = linspace (-1,1);
y = linspace (0,pi/2);
[x,y] = meshgrid (x,y);
zlim ([0 1]);
z = x.^2 *cos(y);

I only want values of z ranging from 0 to 1. How can i do that? Thanks.

Upvotes: 0

Views: 64

Answers (1)

Yuval Harpaz
Yuval Harpaz

Reputation: 1426

Is this what you meant? here zlim crops the image where you choose

x = linspace (-1,1);
y = linspace (0,pi/2);
for ii = 1:length(x)
    for jj = 1:length(y)
        z(ii,jj) = x(ii).^2 *cos(y(jj));
    end
end
figure;
mesh(x,y,z)
zlim ([0 1]);
xlabel('x')
ylabel('y')
zlabel('z')

Upvotes: 1

Related Questions