The surface I'm plotting comes out jagged and "saw teeth" like

65 views (last 30 days)
the surface I plot, using Surf command comes out pointy and jagged, and it ruines the visual presentation and creates an illution the data is spoiled.
I checked the points via contour and saw that the data is fine - the outpoot is smooth and there are no NaN values.
I also tried trisurf function.
Is there a solution? Or is it just a bug I have to deal with?
the good side:
the bad side:
thank you very much!
  3 Comments
Star Strider
Star Strider on 21 Dec 2025 at 16:05
I am not certain what the problem is.
One option would be to interpolate the matrices to finer grids (or at least different grids, depending on what the problem is), and using an interpolation method other than 'linear'. MATLAB has several matrix interpolation functions that could make this straightforward.
boaz
boaz on 24 Dec 2025 at 9:07
Hey,
thanks for answering, here are the attached data files, and relevant code lines.
The Code:
%% calculating the color map
C_h = surface_color(h, "abyss");
C_h = reshape(C_h,[m,n,3]);
%% main plot - surface
subplot(4,4,[1 2 5 6 9 10 13 14]) %plot h
cla
grid on
S = surf(X,Y,h,C_h);
S.EdgeColor = 'none';
shading interp
lighting gouraud

Sign in to comment.

Accepted Answer

Matt J
Matt J on 24 Dec 2025 at 10:46
Edited: Matt J on 24 Dec 2025 at 10:55
It's a very coarsely sampled surface. There's not really any more to it. You can bicubicly upsample the data if you want a smoother appearance:
load stuff
figure;
S = surf(x,y,h,'EdgeAlpha',0.3);
view(-84,84)
figure;
H=interp2(h,3,'bicubic') ;
X=linspace(x(1), x(end),width(H));
Y=linspace(y(1), y(end),height(H));
surf(X,Y,H,'EdgeAlpha',0.3)
view(-84,84)
  2 Comments
boaz
boaz on 24 Dec 2025 at 13:22
Thanks :)
I delibiratly gave a coarse sample so the problem would be more visible. It also happens with finer mash.
I guess it is a matter of the order that matlab draws the lines between data points.
Even when using interpolation, there are "pointy" edges in the surface, even though much less prominent.
Matt J
Matt J on 24 Dec 2025 at 18:06
Show us. With bicubic interpolation, that should be possible only if the data is piecewise linear over a broad swath of samples in the region of the pointy edge.

Sign in to comment.

More Answers (0)

Products


Release

R2024a

Community Treasure Hunt

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

Start Hunting!