ScatteredInterpolant for Surface Extrapolation
17 次查看(过去 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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1131395/image.png)
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!