scatteredInterpolant

Interpolant object for scattered data in 2-D or 3-D.

Category: Mathematics > Interpolation

Syntax

F = scatteredInterpolant(x, y, v)

Creates a 2-D interpolant from sample points (x,y) and values v.

F = scatteredInterpolant(x, y, z, v)

Creates a 3-D interpolant.

F = scatteredInterpolant(..., method, extrapMethod)

Selects 'linear', 'nearest' or 'natural' interpolation and the extrapolation method.

vq = F(xq, yq)

Evaluates the interpolant.

Description

The object triangulates the sample points once and then evaluates quickly at any number of query points. Unlike griddata, it can also extrapolate outside the convex hull, and its Values property can be replaced without redoing the triangulation.

The 'nearest' method returns the value of the closest sample, so the result is piecewise constant.

Input arguments

x, y, z
Coordinates of the sample points, column vectors of equal length.
v
Sample values.
method
Interpolation method, default 'linear'.

Output arguments

F
Interpolant object with properties such as Points, Values, Method and ExtrapolationMethod.

Example

Linear and nearest interpolation of a plane

[x, y] = meshgrid(0:2);
v = x + 2*y;
F = scatteredInterpolant(x(:), y(:), v(:));
F(0.5, 1.5)
F.Method
N = scatteredInterpolant(x(:), y(:), v(:), 'nearest');
N(0.4, 0.4)
Output
ans = 3.5000
ans = 'linear'
ans = 0

See also

griddata griddedInterpolant delaunay interp2