Clear Filters
Clear Filters

3D mesh - Limit Z axis height, but just for the function, not the entire 3D domain

7 views (last 30 days)
I'm trying to draw a parabola in 3D. However, I want to limit its extents.
I am able to limit the X and Y extents pretty easily, through the function.
ie: which limits the x to 0 to 2, and the y from -5 to 1.
X=linspace(0,2,20);
Y=linspace(-5,1,20);
However, the Z, I want to limit this aswell. So I used:
zlim([0 4])
It worked, but now my entire 3D domain is cropped! and I need to show other elements.
Any idea on how this can be achieved? I suspect my function is a bit primitive.
Sorry, I'm matlab illiterate but just starting out. I don't know enough to ask this question properly. THANK YOU for any Help!
total code:
%Curve, parabola in 3d, with limits
X=linspace(0,2,20);
Y=linspace(-5,1,20);
[X,Y]=meshgrid(X,Y);
Z=((Y.^2));
surf(X,Y,Z);
%Limit the Z axis
zlim([0 4])
%basic graphics
x1=[-3 3 3 -3];
y1=[0 0 0 0];
z1=[0 0 6 6];
patch(x1,y1,z1, [0.71 0.72 .73]);
rotate3d on

Accepted Answer

Matt J
Matt J on 11 May 2022
Edited: Matt J on 11 May 2022
One possibility.
X=linspace(0,2,20);
Y=linspace(-5,1,20);
[X,Y]=meshgrid(X,Y);
Z=((Y.^2));
Z(Z>=4)=nan;
surf(X,Y,Z);
%basic graphics
x1=[-3 3 3 -3];
y1=[0 0 0 0];
z1=[0 0 6 6];
patch(x1,y1,z1, [0.71 0.72 .73]);
view(-75,25);
  3 Comments
Matt J
Matt J on 11 May 2022
You're very welcome, but please Aceept-click the answer to certify that it worked.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!