Documentation Center

  • Trial Software
  • Product Updates

scatteredInterpolant class

Scattered data interpolation

Description

Use scatteredInterpolant to perform interpolation on a 2-D or 3-D Scattered Data set. For example, you can pass a set of (x,y) points and values, v, to scatteredInterpolant, and it returns a surface of the form v = F(x, y). This surface always passes through the sample values at the point locations. You can evaluate this surface at any query point, (xq,yq), to produce an interpolated value, vq.

Use scatteredInterpolant to create the Interpolant, F. Then, you can evaluate F at specific points using any of the following syntaxes:

  • Vq = F(Pq) specifies the query points in the matrix Pq. Each row in Pq contains the coordinates of a query point.

  • Vq = F(Xq,Yq) and Vq = F(Xq,Yq,Zq) specify the query points as two or three matrices of equal size.

  • Vq = F({xq,yq}) and Vq = F({xq,yq,zq}) specify the query points as Grid Vectors. The interpolated values are returned in Vq. Use this syntax to conserve memory when you want to query a large grid of points.

Construction

F = scatteredInterpolant(x,y,v) creates an interpolant that fits a surface of the form v = F(x,y). Vectors x and y specify the (x,y) coordinates of the sample points. v is a vector that contains the sample values associated with the points, (x,y).

F = scatteredInterpolant(x,y,z,v) creates a 3-D interpolant of the form v = F(x,y,z).

F = scatteredInterpolant(P,v) specifies the coordinates of the sample points as an array. The rows of P contain the (x, y) or (x, y, z) coordinates for the values in v.

F = scatteredInterpolant(___,Method) specifies a string that describes an interpolation method: 'nearest', 'linear', or 'natural'. Specify Method as the last input argument in any of the first three syntaxes.

F = scatteredInterpolant(___,Method,ExtrapolationMethod) specifies both the interpolation and extrapolation methods as strings. Method can be one of three strings: 'nearest', 'linear', or 'natural'. Specify ExtrapolationMethod as one of the following strings: 'nearest', 'linear', or 'none'. Pass Method and ExtrapolationMethod together as the last two input arguments in any of the first three syntaxes.

F = scatteredInterpolant() creates an empty scattered data interpolant. Use F.Points = P to initialize F with the points in matrix P. Use F.Values = v to initialize F with the values in v.

Input Arguments

x

Sample points x-coordinates, specified as a vector of the same size as v.

y

Sample points y-coordinates, specified as a vector of the same size as v.

z

Sample points z-coordinates, specified as a vector of the same size as v.

P

Sample points array, specified as an m-by-n matrix, where m is the number of points and n is the dimension of the space where the points reside. Each row of P contains the (x, y) or (x, y, z) coordinates of a sample point.

v

Sample values vector, specified as a vector of that defines the values at the sample points.

Method

Interpolation method, specified as one of these strings.

Method StringDescription
'linear' (default)

Linear interpolation.

'nearest'

Nearest neighbor interpolation.

'natural'

Natural neighbor interpolation.

ExtrapolationMethod

Extrapolation method, specified as one of these strings.

ExtrapolationMethod StringDescription
'linear'

Linear extrapolation based on boundary gradients. Default when Method is 'linear' or 'natural'.

'nearest'

Nearest neighbor extrapolation. This method evaluates to the value of the nearest neighbor on the boundary. Default when Method = 'nearest'.

'none'

No extrapolation. Any queries outside the convex hull of F.Points return NaN.

Properties

Points

Array of sample points (locations) for the values in F.Values. Each row of F.Points contains the (x, y) or (x, y, z) coordinates of a sample point.

Values

Vector of values associated with each point in F.Points.

Method

A string specifying the method used to interpolate the data: 'nearest', 'linear', or 'natural'.

ExtrapolationMethod

A string specifying the method used to extrapolate the data: 'nearest', 'linear', or 'none'. A value of 'none' indicates that extrapolation is disabled.

Definitions

Interpolant

Interpolating function that you can evaluate at query locations.

Scattered Data

A set of points that have no structure among their relative locations.

Full Grid

A grid represented as a set of arrays. For example, you can create a full grid using ndgrid.

Grid Vectors

A set of vectors that serve as a compact representation of a grid in ndgrid format. For example, [X,Y] = ndgrid(xg,yg) returns a full grid in the matrices X and Y. You can represent the same grid using the grid vectors, xg and yg.

Copy Semantics

Value. To learn how value classes affect copy operations, see Copying Objects in the MATLAB® documentation.

Indexing

scatteredInterpolant supports index-based editing of the properties of F. You can add or remove points in F.Points and update the corresponding values in F.Values. For example, F.Points(5,:) = [] removes the fifth point, and F.Values(5) = [] removes the corresponding value.

Examples

expand all

2-D Interpolation

Define 200 random points.

xy = -2.5 + 5*gallery('uniformdata',[200 2],0);
x = xy(:,1);
y = xy(:,2);

Sample an exponential function. These are the sample values for the interpolant.

v = x.*exp(-x.^2-y.^2);

Create the interpolant.

F = scatteredInterpolant(x,y,v);

Evaluate the interpolant at query locations ( $xq$ , $yq$ ).

ti = -2:.25:2;
[xq,yq] = meshgrid(ti,ti);
vq = F(xq,yq);

Plot the result.

figure
mesh(xq,yq,vq);
hold on;
plot3(x,y,v,'o');
hold off;

2-D Extrapolation

Query the interpolant at a single point outside the convex hull using nearest neighbor extrapolation.

Define a matrix of 200 random points.

P = -2.5 + 5*gallery('uniformdata',[200 2],0);

Sample an exponential function. These are the sample values for the interpolant.

x = P(:,1);
y = P(:,2);
v = x.*exp(-x.^2-y.^2);

Create the interpolant, specifying linear interpolation and nearest neighbor extrapolation.

F = scatteredInterpolant(P,v,'linear','nearest')
F = 

  scatteredInterpolant with properties:

                 Points: [200x2 double]
                 Values: [200x1 double]
                 Method: 'linear'
    ExtrapolationMethod: 'nearest'

Evaluate the interpolant outside the convex hull.

vq = F(3.0,-1.5)
vq =

    0.0031

Disable extrapolation and evaluate F at the same point.

F.ExtrapolationMethod = 'none';
vq = F(3.0,-1.5)
vq =

   NaN

Replacement of Sample Values

Replace the elements in the Values property when you want to change the values at the sample points. You get immediate results when you evaluate the new interpolant because the original triangulation has not changed.

Create 50 random points.

x = -2.5 + 5*gallery('uniformdata',[50 1],0);
y = -2.5 + 5*gallery('uniformdata',[50 1],1);

Sample an exponential function. These are the sample values for the interpolant.

v = x.*exp(-x.^2-y.^2);

Create the interpolant.

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

  scatteredInterpolant with properties:

                 Points: [50x2 double]
                 Values: [50x1 double]
                 Method: 'linear'
    ExtrapolationMethod: 'linear'

Evaluate the interpolant at (1.40,1.90).

F(1.40,1.90)
ans =

    0.0029

Change the interpolant sample values.

vnew = x.^2 + y.^2;
F.Values = vnew;

Evaluate the interpolant at (1.40,1.90).

F(1.40,1.90)
ans =

    6.1109

See Also

| | | | |

How To

Was this topic helpful?