Why does my surface have a 'jagged' look when I do this?

조회 수: 10 (최근 30일)
A
A 2015년 4월 29일
편집: pfb 2015년 4월 30일
Hi guys,
I think I have successfully done this. However, I would like to know the reason why I get a 'jagged' appearance on the bottom surface? and is there a way to make it smoother? Here's the code:
x = [0:100];
y = [0:100];
Test1 = @(x,y)(x+y);
Test2 = @(x,y)(x.^2+y);
[X1,Y1] = meshgrid(x,y);
Z1 = Test1(X1,Y1);
Z2 = Test2(X1,Y1);
i = Z1<50;
Z1(i)=NaN;
s1 = surf(X1,Y1,Z1);
hold on
i = Z2>=50;
Z2(i)=NaN;
s2 = surf(X1,Y1,Z2);
Thanks

답변 (2개)

Joseph Cheng
Joseph Cheng 2015년 4월 30일
It is due to the spacing of your points. the data is being graphed in a grid so you're not going to have a nice straight line connecting the diagonals of the grid. you can reduce the jagged appearance by decreasing the spacing of the points. for instance if you try running your code with
x = [0:.5:100];
y = [0:.5:100];
you'll see that the jaggedness is decreased
  댓글 수: 2
A
A 2015년 4월 30일
Thanks very much. That makes sense. However, when I do that, the figure goes 'very' black. I think it's probably because of the lines? Is there a way to adjust the way lines are drawn so that you only see a line at intervals of 1?
Brendan Hamm
Brendan Hamm 2015년 4월 30일
No, but you can turn the lines off.
surf(X1,Y1,Z1,'LineStyle','none')

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


pfb
pfb 2015년 4월 30일
편집: pfb 2015년 4월 30일
Hi
Of course, making the grid thicker reduces the jaggedness.
As far as you are plotting planes, you can easily obtain nicer results.
Since these are planar manifolds, you can use one large patch instead of many small patches as in surf.
For that, look into "patch" or "fill3".
If you insist on using surf, you can use a grid adapted to your plane. That is: one of the directions should be the projection of the isolines, the other orthogonal to that (greatest gradient). You can see that when your plane depends only on X or Y. That should work also on your X.^2+Y, although you might want to use different spacings along the two lines.
Finally, you can perhaps use a triangulation for the original mesh. Look at "trisurf" and "delaunay".
Update I just realized you need to use a slightly different strategy for that.
For instance
x = [0:100];
y = [0:100];
Test1 = @(x,y)(x+y);
Test2 = @(x,y)(x.^2+y);
[X1,Y1] = meshgrid(x,y);
Z2 = Test2(X1,Y1);
i = Z2<=50;
X1=X1(i);
Y1=Y1(i);
Z2=Z2(i);
tri=delaunay(X1,Y1);
trisurf(tri,X1,Y1,Z2);
This eliminates the jaggedness. Also, I think you do not need a very thick grid for a nice result.

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by