griddata
Interpolates scattered data at query points.
Category: Mathematics > Interpolation
Syntax
vq = griddata(x, y, v, xq, yq)
Linear interpolation of the scattered samples v(x,y) at the points (xq,yq).
vq = griddata(x, y, v, xq, yq, method)
Uses the given method, such as 'nearest', 'linear', 'natural', 'cubic' or 'v4'.
vq = griddata(x, y, z, v, xq, yq, zq)
The same for samples in three dimensions.
Description
griddata builds a Delaunay triangulation of the sample points and interpolates inside each triangle. The data need not lie on a regular grid, which distinguishes it from interp2.
The linear method is exact for data that come from a plane. The nearest method copies the value of the closest sample and is the only one that returns finite values outside the hull. For repeated queries on the same data, scatteredInterpolant avoids rebuilding the triangulation.
Input arguments
x, y- Coordinates of the sample points, vectors of equal length.
v- Sample values at those points.
xq, yq- Query coordinates. Vectors of the same shape give values at those points; a row and a column vector define a grid.
method- Interpolation method, default
'linear'.
Output arguments
vq- Interpolated values. Points outside the convex hull of the samples give
NaN, except for the'nearest'method.
Example
Interpolating samples of a plane
[x, y] = meshgrid(0:2);
v = x + 2*y;
griddata(x(:), y(:), v(:), 0.5, 1.5)
griddata(x(:), y(:), v(:), [0.4 1.6], [0.4 1.6], 'nearest')
Output
ans = 3.5000
ans = 1×2
0 6