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

7 次查看(过去 30 天)
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

采纳的回答

Matt J
Matt J 2022-5-11
编辑:Matt J 2022-5-11
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Programming 的更多信息

标签

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by