Is it possible to make a surface perfectly proper?

1 次查看(过去 30 天)
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 个评论
Image Analyst
Image Analyst 2022-2-6
Do you mean that you want to find the best-fit plane that goes through all those wildly varying points?
Ege Ulus
Ege Ulus 2022-2-6
编辑:Ege Ulus 2022-2-6
Yes, best fit hyperbolic paraboloid, elliptical, etc. surfaces are also accepted.

请先登录,再进行评论。

采纳的回答

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

更多回答(2 个)

Simon Chan
Simon Chan 2022-2-6
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 2022-2-6
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.

类别

Help CenterFile Exchange 中查找有关 Surface and Mesh Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by