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
2022년 2월 6일
Do you mean that you want to find the best-fit plane that goes through all those wildly varying points?
채택된 답변
Burhan Burak AKMAN
2022년 2월 6일
You can change interpolation method.
zGrid = griddata(X(:),Y(:),Z(:),xGrid(:),yGrid(:),'v4');
추가 답변 (2개)
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
댓글 수: 0
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!