Main Content

hdl.interpn

Find interpolated value based on n-dimensional input data

Since R2024b

    Description

    Vq = hdl.interpn(X1,X2,...,Xn,V,Xq1,Xq2,...,Xqn) returns the interpolated values of a function of n variables at a specific query point using linear interpolation and linear extrapolation. X1,X2,...,Xn contain the coordinates of the sample points in each dimension. V contains the corresponding function values at each sample point. Xq1,Xq2,...,Xqn contain the coordinates of the query point.

    example

    Vq = hdl.interpn(X1,X2,...,Xn,V,Xq1,Xq2,...,Xqn,interpolation,extrapolation) also specifies interpolation and extrapolation approximation methods.

    example

    Examples

    collapse all

    Define the sample points and values.

    X = [1 2 3 4 5];
    V = [12 16 31 10 6];

    Define the query point, Xq, and find the interpolated value for this point.

    Xq = 4.3;
    Vq = hdl.interpn(X,V,Xq);
    Vq 
    = 8.8000;

    Define the sample points and values. Initialize the random number generator by using the default generator algorithm and seed. For more information, see rng.

    X1 = 1:30; X2 = -10:10; X3 = 1:5; X4 = 10:13;
    rng("default");
    V = rand(30,21,5,4);

    Define the query point, Xq, and find the interpolated value for this point.

    Xq1 = 35; Xq2 = 20; Xq3 = 10; Xq4 = 1;
    Vq = hdl.interpn(X1,X2,X3,X4,V,Xq1,Xq2,Xq3,Xq4,"linear","nearest");
    Vq 
    = 0.7811;

    Input Arguments

    collapse all

    Sample points, specified as real arrays or vectors. The sample points within each argument must be unique.

    Example: [X1,X2,X3,X4] = [1:30,-10:10,1:5,10:13]

    Data Types: single | double

    Sample values, specified as a real array. The dimensions of V must be the same as sizes of the sample point arrays X1,X2,...,Xn.

    Example: rand(10,5,3,2)

    Data Types: single | double

    Coordinates of query point, specified as real scalars.

    Example: [Xq1,Xq2,Xq3,Xq4] = [35 20 10 1]

    Data Types: single | double

    Interpolation method, specified as "linear".

    Data Types: char | string

    Extrapolation method, specified as "linear" or "nearest".

    Data Types: char | string

    Output Arguments

    collapse all

    Interpolated value, returned as a real scalar.

    Extended Capabilities

    Version History

    Introduced in R2024b