1
votes

I have a geographically distributed data set with X-coordinate, Y-coordinate and corresponding target value of interest D. That is, my data set consists from three vectors: X, Y, D.

Now what I would like to do, is interpolate and extrapolate the target variable D over a coordinate grid of interest. The griddata-function in Matlab seems to be able to help me in this problem, but it only does interpolation over the convex hull determined by my data set.

What I would like to do, is to also extrapolate the data D to any rectangular coordinate grid of interest like so:

enter image description here

I have tried using functions like interp2 and griddedInterpolant, but these functions seem to require that I provide the known data as monotonic matrices (using e.g. meshgrid). That is, if I have understood correctly, I must provide X,Y,D as 2D-grids. But they are not grids, they are non-monotonic vectors.

So how can I proceed?

2
griddata and then interp2 on the regular output of griddata?Ander Biguri
@AnderBiguri I will try that, thank you :)jjepsuomi
@AnderBiguri unfortunately I couldn't get it to work. Maybe a MWE?jjepsuomi

2 Answers

1
votes

You can use griddata with option 'v4' that uses biharmonic spline interpolation.

Unlike the other methods, this interpolation is not based on a triangulation.

Other option is using scatteredInterpolant. You can choose to use any of 'linear' or 'nearest' methods for extrapolation

1
votes

I found out one way using scatteredInterpolant:

xy = -2.5 + 5*gallery('uniformdata',[200 2],0);
x = xy(:,1);
y = xy(:,2);
v = x.*exp(-x.^2-y.^2);
F1 = scatteredInterpolant(x,y,v, 'natural');
[xq,yq] = ndgrid(-5:.1:5) % Make the grid
vq1 = F1(xq,yq); % Evaluate function values at grid of interest
surf(xq,yq,vq1)
hold on
plot3(x,y,v, 'ro', 'MarkerFaceColor', 'red')
xlabel('X')
ylabel('Y')
zlabel('V')
title('Interpolation and exrapolation based on scattered data')

enter image description here

The problem is, you can do extrapolation with only three methods: 'linear', 'nearest', 'natural'.