ScatteredInterpolant for Surface Extrapolation

21 views (last 30 days)
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 Comments
KSSV
KSSV on 21 Sep 2022
Edited: KSSV on 21 Sep 2022
Extrapolation cannot be trusted. You specify the method as nearest.
MATLAB_Soldier
MATLAB_Soldier on 21 Sep 2022
Nearest method gives poor results. It is very unrealistic. Look at the plot below, values extrapolated to 2000.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 21 Sep 2022
Edited: Matt J on 21 Sep 2022
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(:));
Local minimum possible. lsqcurvefit stopped because the size of the current step is less than the value of the step size tolerance.
[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)
vq1 = 21×1
0.2207 0.6207 1.0277 1.4359 1.8391 2.2305 2.6032 2.9503 3.2649 3.5407
scatter3(MAP_X(:),MAP_Y(:),MAP_Z(:)); hold on
scatter3(xq,yq,vq1); hold off
xlabel x
ylabel y
view(-60,15)
  1 Comment
MATLAB_Soldier
MATLAB_Soldier on 21 Sep 2022
Moved: Bruno Luong on 21 Sep 2022
Thank you very much for your help guys and for the excellent explanation Walter Robinson.

Sign in to comment.

More Answers (2)

Walter Roberson
Walter Roberson on 21 Sep 2022
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.

Matt J
Matt J on 21 Sep 2022
Edited: Matt J on 21 Sep 2022
[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)
vq1 = 21×1
0.3633 1.2500 1.8567 2.3700 3.0967 4.0767 4.1833 4.1900 4.3800 5.1400
scatter3(MAP_X(:),MAP_Y(:),MAP_Z(:)); hold on
scatter3(xq,yq,vq1); hold off

Categories

Find more on Delaunay Triangulation in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!