ILNumerics Ultimate VS

Interpolationinterp2 Method (InArrayDouble, InArrayDouble, InArrayDouble, InArrayDouble, InArrayDouble, Int32, InterpolationMethod)

ILNumerics Ultimate VS Documentation
ILNumerics - Technical Application Development
Interpolate query points on a regular grid from gridded 2D data.

[ILNumerics Interpolation Toolbox]

Namespace:  ILNumerics.Toolboxes
Assembly:  ILNumerics.Toolboxes.Interpolation (in ILNumerics.Toolboxes.Interpolation.dll) Version: 5.5.0.0 (5.5.7503.3146)
Syntax

public static RetArray<double> interp2(
	InArray<double> V,
	InArray<double> X1 = null,
	InArray<double> X2 = null,
	InArray<double> Xn1 = null,
	InArray<double> Xn2 = null,
	int k = 0,
	InterpolationMethod method = InterpolationMethod.linear
)

Parameters

V
Type: ILNumericsInArrayDouble
Matrix with sample values defined in meshgrid format.
X1 (Optional)
Type: ILNumericsInArrayDouble
[Optional] Positions of grid points along the rows of V, specified as a matrix in meshgrid format or grid vector. Monotonically increasing along the rows.
X2 (Optional)
Type: ILNumericsInArrayDouble
[Optional] Positions of grid points along the columns of V, specified as a matrix in meshgrid format or grid vector. Monotonically increasing along the columns.
Xn1 (Optional)
Type: ILNumericsInArrayDouble
[Optional] Query point positions for dimension 1 (rows), specified as grid vector or matrix in meshgrid format. Monotonically increasing.
Xn2 (Optional)
Type: ILNumericsInArrayDouble
[Optional] Query point positions for dimension 2 (columns), specified as grid vector or matrix in meshgrid format. Monotonically increasing.
k (Optional)
Type: SystemInt32
[Optional] Refinement factor for default query grid positions. Ranges specified by X1 and/or X2 are split k times. Ignored for Xn1 or Xn2 being not null respectively. Default: 1.
method (Optional)
Type: ILNumerics.ToolboxesInterpolationMethod
[Optional] Interpolation method. Default: linear.

Return Value

Type: RetArrayDouble
Matrix with interpolated values. Corresponds to the grid determined by Xn1 and Xn2.
Exceptions

ExceptionCondition
ArgumentNullExceptionIf input parameter V is NULL
ArgumentExceptionIf argument X1 or X2 are not not strictly monotonically increasing.
ArgumentExceptionIf argument method is set as global polynomial for more than 9 sample points X1 or X2
ArgumentOutOfRangeExceptionIf arguments X1 or X2 do not match the size of V.
Remarks

interp2(InArrayDouble, NullableDouble, InArrayDouble, InArrayDouble, InArrayDouble, InArrayDouble, Int32, InterpolationMethod) performs two dimensional interpolation over the given data matrix V defined in meshgrid(InArrayDouble, InArrayDouble, InArrayDouble, OutArrayDouble, OutArrayDouble) format. The parameter X1 specifies the positions of the grid points in V along the first dimension (along the rows of V). X2 determines the positions along the 2nd dimension (along the columns of V). Hence, V forms a regular, rectilinear grid of (non-)uniform spacing. Note the order of the dimensions in V: as determined by the meshgrid function the first dimension is considered to correspond to the rows instead of the columns. This order is useful for visualization purposes and plotting, where the X axis is commonly expected along the rows. Use interpn(InArrayDouble, NullableDouble, InCell, InCell, InterpolationMethod) as an alternative.

Values in X1 and X2, if provided, must be strictly monotonically increasing but not necessarily be uniform. If any of X1 and/or X2 are ommitted, default grid positions are assumed with uniform range of spacing 1: 0:n x 0:m, where [m+1,n+1] = size(V).

Values in Xn1 and Xn2, if provided, must be strictly monotonically increasing but not necessarily uniform. If any of Xn1 and/or Xn2 are ommitted, default query grid positions are assumed by subdividing X1 and/or X2 respectively, 'k' times.

Interpolation methods: all methods from the enum InterpolationMethod are supported. See interp1(InArrayDouble, NullableDouble, InArrayDouble, InArrayDouble, Int32, InterpolationMethod) for a detailed description.

By default interp2(InArrayDouble, InArrayDouble, InArrayDouble, InArrayDouble, InArrayDouble, Int32, InterpolationMethod) assigns NaN to all query points laying outside of the range of X1 and X2. Use the overload interp2(InArrayDouble, NullableDouble, InArrayDouble, InArrayDouble, InArrayDouble, InArrayDouble, Int32, InterpolationMethod) with an additional 'outOfRange' parameter in order to specify another value for out-of-range points or to create extrapolated values for them by specifying the outOfRange parameter as null.

[ILNumerics Interpolation Toolbox]

Examples

//generate any meshgrid
Array<double> X2 = 1;
Array<double> X1 = meshgrid(linspace<Double>(-2, 2, 20), linspace<Double>(-2, 2, 20), X2);
Array<double> V = X1 * exp(-(X1 * X1 + X2 * X2));

//define query meshgrid
Array<double> Xn2 = 1;
Array<double> Xn1 = meshgrid(linspace<Double>(-3, 3, 50), linspace<Double>(-3, 3, 50), Xn2);

//Interpolate
Array<double> Vq = Interpolation.interp2(V, X1, X2, Xn1, Xn2, method:InterpolationMethod.spline, outOfRangeValues: double.NaN);

//or spline interpolate using refinement factor
Array<double> Vq = Interpolation.interp2(V, X1, X2, k:2, method:InterpolationMethod.spline);

//or nearest neighbor interpolation of a meshgrid with only one Xn2 specified.
Array<double> Vq = Interpolation.interp2(V, X1, X2, Xn2:Xn2, method:InterpolationMethod.nearest);

//or linear interpolate a meshgrid
Array<double> Vq = Interpolation.interp2(V);

See Also

Reference