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

7 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Matt J
Matt J am 11 Mai 2022
Bearbeitet: Matt J am 11 Mai 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 Kommentare
Matt J
Matt J am 11 Mai 2022
You're very welcome, but please Aceept-click the answer to certify that it worked.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by