griddedInterpolant

Interpolant object for data sampled on a grid.

Category: Mathematics > Interpolation

Syntax

F = griddedInterpolant(x, v)

Creates a 1-D interpolant over the grid vector x with values v (linear method).

F = griddedInterpolant(X1, X2, ..., V)

Creates an interpolant on an N-D grid given by grid vectors or ndgrid arrays.

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

Selects the interpolation method and the extrapolation method.

vq = F(xq)

Evaluates the interpolant at the query points.

Description

The object stores the grid and the values once, so evaluating it many times is cheaper than repeated calls to interp1 or interpn. Evaluation uses parenthesis syntax, F(xq) for one dimension or F(xq, yq) for two.

The Values and GridVectors properties can be read and changed after creation, for instance to reuse the same grid with new data.

Input arguments

x, X1, ...
Sample coordinates along each dimension, strictly increasing.
V
Array of sample values, with one value for every grid point.
method
'linear' (default), 'nearest', 'next', 'previous', 'pchip', 'cubic', 'spline' or 'makima'.
extrapMethod
Method used outside the grid; by default the interpolation method. Use 'none' to get NaN there.

Output arguments

F
Interpolant object with properties such as GridVectors, Values and Method; call it like a function.

Example

Linear and spline interpolants of x^2

x = 1:4;
v = x.^2;
F = griddedInterpolant(x, v, 'linear');
F(2.5)
S = griddedInterpolant(x, v, 'spline');
S(2.5)
F.Values
Output
ans = 6.5000
ans = 6.2500
ans = 1×4

     1     4     9    16

See also

interp1 interpn scatteredInterpolant spline ndgrid