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
Matt J
Matt J 2022년 5월 11일
You're very welcome, but please Aceept-click the answer to certify that it worked.

댓글을 달려면 로그인하십시오.

추가 답변 (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