Is it possible to make a surface perfectly proper?

2 vues (au cours des 30 derniers jours)
Ege Ulus
Ege Ulus le 6 Fév 2022
Commenté : Ege Ulus le 14 Fév 2022
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 commentaires
Image Analyst
Image Analyst le 6 Fév 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 le 6 Fév 2022
Modifié(e) : Ege Ulus le 6 Fév 2022
Yes, best fit hyperbolic paraboloid, elliptical, etc. surfaces are also accepted.

Connectez-vous pour commenter.

Réponse acceptée

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

Plus de réponses (2)

Simon Chan
Simon Chan le 6 Fév 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 le 6 Fév 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!

Translated by