Problem to get the right format of a Surf Plot

I am trying to plot a surface. What I need is the surface that is on top, but I keep getting the two surfaces underneath. Is there any reason why this is happening?
BB = [TBfunc1;TBfunc2]
X = [BB(:,1)]
Y = [BB(:,3)]
Z = [BB(:,2)]
[xi, yi] = meshgrid(X,Y);
F = scatteredInterpolant(X,Y,Z)
zi = F(xi,yi)
surf(xi,yi,zi, 'EdgeAlpha', 0)

 Accepted Answer

It looks as though ‘X’ is not sorted. Without the data a guess would be this possible solution:
BB = sortrows (BB,1);
See the documentation on sortrows for details.

6 Comments

Thank you so much, it worked! :)
As always, my pleasure!
I’m not certain what the problem is.
It would definitely help to have your data to experiment with, however lacking that, one other possibility is to use the unique function with the 'rows' option argument. Note that it will also sort them (that will likely be what you want to do anyway) unless you tell it not to with the 'stable' set order argument.
I’m not certain what it’s supposed to look like.
Try this (just after creating ‘BB’):
BB = sortrows(BB,1);
or:
BB = sortrows(BB,3);
and see it one of those does what you want.
Those appear to me to be acceptable, in that they eliminiate the ‘fold’ in the surf plot.
Thank you again, for your support! I managed to fix it by myself. Is was an issue with the meshgrid size.
As always, my pleasure!

Sign in to comment.

More Answers (0)

Products

Asked:

Cb
on 26 Feb 2021

Commented:

on 8 Mar 2021

Community Treasure Hunt

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

Start Hunting!