I want draw a graph correctly

I write code like this
function z = F3(x,y)
z = 4- x.^2- 2*y.^2;
figure(1)
[X,Y] = meshgrid(0:0.1:2);
mesh(X,Y,F3(X,Y))
axis([0 2 0 2 0 6])
and than
graph is came out like this
I don't want to see value of Z under '0'
How can I do that??
Thought I give the value of the Z axis range from 0 to 6, but it is steel came out like this ,,,

댓글 수: 3

C.J. Harris
C.J. Harris 2016년 1월 18일
Which version of MATLAB are you using?
pty0220
pty0220 2016년 1월 19일
R2014a for mac thanks ~
Walter Roberson
Walter Roberson 2016년 1월 19일
I confirm that with that release on Mac I see the same results. The clipping property of the axes is seemingly being ignored.

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

답변 (1개)

Thorsten
Thorsten 2016년 1월 18일

0 개 추천

With your axis command you cut off the z values at 0 (with the third 0 in axis([0 2 0 2 0 6]). Instead, use:
Z = F3(X,Y);
mesh(X,Y,Z);
axis([0 2 0 2 min(Z(:)) max(Z(:))])

댓글 수: 3

pty0220
pty0220 2016년 1월 19일
I want to cut off the Z values at 0
but it's not completely cut off at Z = 0
graph is came out out side of the graph that's my problem ,,, T.T
I see. You could set the negative Z values to 0 or NaN:
Z(Z<0) = 0;
or
Z(Z<0) = NaN;
In the first case you have the a mesh at the positions were Z < 0, with NaN the cut-off is ragged. So both solutions may be better than the original plot, but they are not perfect.
Mike Garrity
Mike Garrity 2016년 1월 19일
편집: Mike Garrity 2016년 1월 19일
You're seeing something called
ClippingStyle = 'rectangle'
In that type of clipping, the geometry is clipped at the 2D rectangle that surrounds the axes. That was the only type of clipping that MATLAB Graphics supported until R2014b. Since that release, you have another choice:
ClippingStyle = '3dbox'
And I think that will actually be the default in this case. So if you upgrade to a newer version, you should get what you want.
In newer versions, if you don't like the clipping style that was chosen for you, you can change it like so:
set(gca,'ClippingStyle','3dbox')
or
set(gca,'ClippingStyle','rectangle')

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

카테고리

도움말 센터File Exchange에서 Graphics Object Properties에 대해 자세히 알아보기

제품

질문:

2016년 1월 18일

편집:

2016년 1월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by