ScatteredInterpolant for Surface Extrapolation
조회 수: 21 (최근 30일)
이전 댓글 표시
Hi Everyone,
I have a set of XYZ data that forms the following plot (surface, not in this case) below.I would like to extrapolate this slightly outside of the region on the X axis, at 2000.
I have used the following code to extrapolate at the value of 2000.
%Input for Extrapolation
xq=zeros(21,1)+2000;
yq=[0:5:95]';
yq(end+1)=99;
F = scatteredInterpolant(MAP_X,MAP_Y,MAP_Z);
vq1=F(xq,yq)
Unfortuntaly, my results are far off from ideal:
vq1 =
0.4740
305.5350
130.4689
-156.4641
-19.2672
86.5564
281.8144
112.3261
-150.5571
534.2845
-219.2750
245.6169
-219.3640
60.4432
-141.4669
252.9336
-181.9238
115.2369
-131.9798
58.5419
4.9041
What is causing this error? How can I fix it?
Is there a better way to extrapolate this dataset?
Many thansk.
댓글 수: 5
채택된 답변
Matt J
2022년 9월 21일
편집: Matt J
2022년 9월 21일
The surface appears to be very well modeled by a Gaussian. An appropriate thing would therefore be to extrapolate using a Gaussian fit, e.g., using this FEX download,
[MAP_X,MAP_Y,MAP_Z]=readvars('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1131415/MATLAB.csv');
res=@(q)reshape(q,21,[])';
MAP_X=res(MAP_X);
MAP_Y=res(MAP_Y);
MAP_Z=res(MAP_Z);
params=gaussfitn([MAP_X(:),MAP_Y(:)],MAP_Z(:));
[D,A,mu,sigma]=deal(params{:});
fcn=@(x,y) D+A*exp(-0.5*sum( ([x-mu(1),y-mu(2)]/sigma).*[x-mu(1),y-mu(2)] ,2));
xq=zeros(21,1)+2000;
yq=[0:5:95]';
yq(end+1)=99;
vq1=fcn(xq,yq)
scatter3(MAP_X(:),MAP_Y(:),MAP_Z(:)); hold on
scatter3(xq,yq,vq1); hold off
xlabel x
ylabel y
view(-60,15)
추가 답변 (2개)
Walter Roberson
2022년 9월 21일
scatteredInterpolant() does not do any kind of surface fitting. The default fitting option that it uses, the one you are getting, is 'linear'. A Delaunay triangulation is done, nearest points on the triangulation found, linear interpolation is done.
Depending on the input coordiantes and the query coordinates, it is not uncommon for the nearest point in the triangulation to be different than expected. It is common for large triangles in Z to be created that cross a lot of the surface. The range of Z values in your surface is small compared to the range of X values.
Near the edge of the surface, extrapolating outside... the interior behaviour of the surface can become pretty much irrelevant. If you do not end up with one of those large spanning triangles just mentioned, if you end up querying against a more local series of triangles, then the rest of the surface might as well not exist. And that implies that small differences in Z values near the outside edge can get magnified to large differences when you query a distance away. For example if you are querying against a couple of surface points that differ by 1/2 in Z coordinates, and you are querying 1000 units away, then by linear interpolation the predicted Z difference would be 500, even though that is much larger than any of the input Z values.
If you could rewrite in terms of griddedInterpolant (since you pretty much have a grid of X and Y) then you would be able to use 'spline' or 'pchip' interpolant.
댓글 수: 0
Matt J
2022년 9월 21일
편집: Matt J
2022년 9월 21일
[MAP_X,MAP_Y,MAP_Z]=readvars('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1131415/MATLAB.csv');
res=@(q)reshape(q,21,[])';
MAP_X=res(MAP_X);
MAP_Y=res(MAP_Y);
MAP_Z=res(MAP_Z);
F=griddedInterpolant(MAP_X,MAP_Y,MAP_Z);
xq=zeros(21,1)+2000;
yq=[0:5:95]';
yq(end+1)=99;
vq1=F(xq,yq)
scatter3(MAP_X(:),MAP_Y(:),MAP_Z(:)); hold on
scatter3(xq,yq,vq1); hold off
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Delaunay Triangulation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!