interpn

Interpolation of data on an N-D grid.

Category: Mathematics > Interpolation

Syntax

Vq = interpn(X1, X2, ..., Xn, V, Xq1, Xq2, ..., Xqn)

Interpolates V sampled on the grid defined by X1, ..., Xn at the query points.

Vq = interpn(V, Xq1, ..., Xqn)

Assumes the grid vectors are 1:size(V,k).

Vq = interpn(..., method, extrapval)

Selects the method and a fill value for points outside the grid.

Description

interpn uses ndgrid orientation: dimension k of V corresponds to the k-th coordinate, so for a matrix the first coordinate runs down the rows. This differs from interp2, which follows meshgrid.

The linear method is multilinear. Other methods include 'nearest', 'cubic', 'spline' and 'makima'.

Input arguments

X1, ..., Xn
Grid vectors, one per dimension, strictly increasing.
V
N-D array of values; dimension k of V follows Xk.
Xq1, ..., Xqn
Query coordinates, with matching shapes.

Output arguments

Vq
Interpolated values; NaN outside the grid unless a fill value is given.

Example

A 3-by-3 table with vector grids

V = magic(3);
interpn(V, 1.5, 2.5)
interpn(1:3, 1:3, V, [1.5 2.5], [1.5 2.5])
Output
ans = 4.7500
ans = 1×2

    4.2500    5.7500

See also

interp2 interp3 ndgrid griddedInterpolant