Is it possible to make a surface perfectly proper?

2 views (last 30 days)
Dear All,
I am getting the graph you see through the code below.
Can I get a plane-like surface with a proper shape like in the attached image without changing the points? I need a proper more evenly shaped surface, even if the surface does not pass through one-to-one points.
D = [288 2.79 7.55;
318 4.64 14.28;
127 2.31 8.31;
132 7.16 17.27;
264 2.31 4.32;
200 2.60 6.74;
268 3.06 15.12];
X = D(:,1);
Y = D(:,2);
Z = D(:,3);
% Create 100x100 grid mesh (x,y) points
[xGrid,yGrid] = meshgrid(linspace(min(X),max(X)),linspace(min(Y),max(Y)));
% Interpolation
zGrid = griddata(X(:),Y(:),Z(:),xGrid(:),yGrid(:),'cubic');
zGrid = reshape(zGrid,size(xGrid));
% Fig.1 Contour plot with original data points
figure
contour(xGrid,yGrid,zGrid,'ShowText','on')
hold on
scatter(X,Y,'ro')
grid on
colorbar
% Fig.2 Surf plot
figure
surf(xGrid,yGrid,zGrid)
colormap(jet)
colorbar
Thanks,
Ege
  2 Comments
Image Analyst
Image Analyst on 6 Feb 2022
Do you mean that you want to find the best-fit plane that goes through all those wildly varying points?
Ege Ulus
Ege Ulus on 6 Feb 2022
Edited: Ege Ulus on 6 Feb 2022
Yes, best fit hyperbolic paraboloid, elliptical, etc. surfaces are also accepted.

Sign in to comment.

Accepted Answer

Burhan Burak AKMAN
Burhan Burak AKMAN on 6 Feb 2022
You can change interpolation method.
zGrid = griddata(X(:),Y(:),Z(:),xGrid(:),yGrid(:),'v4');

More Answers (2)

Simon Chan
Simon Chan on 6 Feb 2022
You may adjust the value of variable 'spacing' in the following code to meet your needs.
I use spacing = 5 as an example, you may try to use 10.
D = [288 2.79 7.55;
318 4.64 14.28;
127 2.31 8.31;
132 7.16 17.27;
264 2.31 4.32;
200 2.60 6.74;
268 3.06 15.12];
X = D(:,1);
Y = D(:,2);
Z = D(:,3);
% Create 100x100 grid mesh (x,y) points
[xGrid,yGrid] = meshgrid(linspace(min(X),max(X)),linspace(min(Y),max(Y)));
% Interpolation
zGrid = griddata(X(:),Y(:),Z(:),xGrid(:),yGrid(:),'cubic');
zGrid = reshape(zGrid,size(xGrid));
% Fig.2 Surf plot
spacing = 5; % Added this variable
figure
surf(xGrid(1:spacing:end,1:spacing:end),yGrid(1:spacing:end,1:spacing:end),zGrid(1:spacing:end,1:spacing:end))
colormap(jet)
colorbar

Image Analyst
Image Analyst on 6 Feb 2022
Try John D'Errico's polyfitn()
It will fit your data to a 2-D polynomial of the order you want, like a plane or parabola.

Community Treasure Hunt

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

Start Hunting!