# scatteredlookup

Return value based on interpolating unstructured set of data points

Since R2023a

Parent Section: equations

## Syntax

```scatteredlookup(x1d, x2d, x3d, fd, x1, x2, x3, extrapolation = linear|nearest)
```

## Description

Use the `scatteredlookup` function in the `equations` section to compute an output value by interpolating the query input value against an unstructured, or scattered, set of data points. Unlike the `tablelookup` function, these data points do not need to form a table grid. You provide the coordinates of a set of input data points and the function value at each of these data points. Then, you provide the coordinates of a query point or points and the `scatteredlookup` function returns the corresponding interpolated function value by using Delaunay triangulation.

The `scatteredlookup` function supports two-dimensional and three-dimensional lookup. The full syntax is:

```scatteredlookup(x1d, x2d, x3d, fd, x1, x2, x3, extrapolation = linear|nearest) ```
 `x1d` Data set of input values along the first direction, specified as a one-dimensional array. Specify at least three values for two-dimensional lookup and at least four values for three-dimensional lookup. This is a required argument. `x2d` Data set of input values along the second direction, specified as a one-dimensional array of the same size as `x1d`. This is a required argument. `x3d` Data set of input values along the third direction, specified as a one-dimensional array of the same size as `x1d`. Use this argument only for the three-dimensional lookup. `fd` Data set of function values for the lookup, specified as a one-dimensional array of the same size as `x1d`. This is a required argument. `x1` The query input value along the first direction, specified as a scalar or as a one-dimensional array. Its units must be commensurate with the units of `x1d`. This is a required argument. `x2` The query input value along the second direction, specified as a scalar or as a one-dimensional array of the same size as `x1`. Its units must be commensurate with the units of `x2d`. This is a required argument. `x3` The query input value along the third direction, specified as a scalar or as a one-dimensional array of the same size as `x1`. Its units must be commensurate with the units of `x3d`. Use this argument only for the three-dimensional lookup. ```extrapolation = linear|nearest``` Optional argument that specifies the approximation method for calculating the output value when the input value is outside the range specified in the lookup table. The default is `extrapolation = linear`.

The `extrapolation` argument values are:

• `linear`— Linear extrapolation based on boundary gradients.

• `nearest` — Nearest neighbor extrapolation. This method evaluates to the value of the nearest neighbor on the boundary.

If the query input values `x1`, `x2`, and `x3` are:

• Scalar, then the function returns a scalar.

• One-dimensional arrays, then the function returns a one-dimensional array of the same size.

## Examples

expand all

This example implements a linear function (2x + 3y) by using a two-dimensional scattered lookup.

```component slu_2d inputs u1; u2; end outputs f; end parameters (Size=variable) x = [1 2 5 3 4 8]; y = [1 7 10 4 4.5 8]; % function values form a linear function 2*x + 3*y fd = [5 25 40 18 21.5 40]; end equations f == scatteredlookup(x, y, fd, u1, u2, extrapolation=nearest); end end```

`x`, `y`, and `fd` are vectors of the same size. The `x` and `y` vectors provide the coordinates of five scattered data points, and for each of these points, `fd` provides the function value. For example, for the first point, 2x1+3x1=5.

The `scatteredlookup` function triangulates the data set. For two-dimensional interpolation, each vector must have at least three values. Providing additional data points helps construct finer triangles and provides better accuracy for linear interpolation.

If the values of inputs `u1` and `u2` are within the convex hull of the `x` and `y` vectors, the function determines the output value by performing linear interpolation inside the corresponding triangle constructed by the triangulation, that is, interpolates the `fd` values at the triangle vertices.

This example specifies `extrapolation=nearest`. Therefore, if the values of inputs `u1` and `u2` are outside the convex hull of the data set, the function provides the `fd` value of the nearest neighbor on the boundary.

## Version History

Introduced in R2023a