tablelookup
Return value based on interpolating set of data points
Parent Section: equations
Syntax
tablelookup(x1d, x2d, x3d, x4d, fd, x1, x2, x3, x4, interpolation = linear|smooth, extrapolation = linear|nearest|error)
Description
Use the tablelookup
function in the
equations
section to compute an output value by
interpolating the query input value against a set of data points. This functionality is
similar to that of the Simulink® and Simscape™ Lookup Table blocks. It allows you to incorporate table-driven modeling
directly in your custom block, without the need of connecting an external Lookup Table
block to your model.
The tablelookup
function supports
one-dimensional, two-dimensional, three-dimensional, and four-dimensional lookup tables.
The full syntax is:
tablelookup(x1d, x2d, x3d, x4d, fd, x1, x2, x3, x4, interpolation = linear|smooth, extrapolation = linear|nearest|error)
| Data set of input values along the first direction, specified as a one-dimensional array. The values must be strictly monotonic, either increasing or decreasing. This is a required argument. |
| Data set of input values along the second direction, specified as a one-dimensional array. The values must be strictly monotonic, either increasing or decreasing. This argument is used only for the two-dimensional, three-dimensional, and four-dimensional table lookup. |
| Data set of input values along the third direction, specified as a one-dimensional array. The values must be strictly monotonic, either increasing or decreasing. This argument is used only for the three-dimensional and four-dimensional table lookup. |
| Data set of input values along the fourth direction, specified as a one-dimensional array. The values must be strictly monotonic, either increasing or decreasing. This argument is used only for the four-dimensional table lookup. |
| Data set of output values for the table lookup. This is a required argument. For one-dimensional table lookup,
For
two-dimensional table lookup, For three-dimensional table lookup,
For four-dimensional table lookup,
|
| The query input value along the first direction, specified as a
scalar or as an N-D array. Its units must be commensurate with the
units of |
| The query input value along the second direction, specified as
a scalar or as an N-D array of the same size as
|
| The query input value along the third direction, specified as a
scalar or as an N-D array of the same size as |
| The query input value along the fourth direction, specified as
a scalar or as an N-D array of the same size as
|
| Optional argument that specifies the approximation method for
calculating the output value when the input value is inside the
range specified in the lookup table. The default is
|
| 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
|
The interpolation
argument values are:
linear
— For one-dimensional table lookup, uses a linear function. For two-dimensional, three-dimensional, and four-dimensional table lookup, uses an extension of linear algorithm for multidimensional interpolation, by performing linear interpolation in the first direction, then in second direction, then in third direction, and then in fourth direction. Use this method to get the best performance.smooth
— Uses a modified Akima algorithm. For more information, seemakima
. Use this method to produce a continuous curve or surface with continuous first-order derivatives.
The extrapolation
argument values are:
linear
— Extends from the edge of the interpolation region linearly. The slope of the linear extrapolation is equal to the slope of the interpolated curve or surface at the edge of the interpolation region. Use this method to produce a curve or surface with continuous value and continuous first-order derivatives at the boundary between the interpolation region and the extrapolation region.nearest
— Extends from the edge of the interpolation region as a constant. The value of the nearest extrapolation is equal to the value of the interpolated curve or surface at the edge of the interpolation region. Use this method to produce a curve or surface with continuous value at the boundary between the interpolation region and the extrapolation region that does not go above the highest point in the data or below the lowest point in the data.error
— Generates an error when the input value is outside the range specified in the lookup table.
The function returns an output value, in the units specified for
fd
, by looking up or estimating table values based on the input
values:
When inputs x1 ,
x2 , x3 , and
x4 ... | The tablelookup function... |
---|---|
Match the values in the input data sets, x1d ,
x2d , x3d , and
x4d | Outputs the corresponding table value, fd |
Do not match the values in the input data sets, but are within range | Interpolates appropriate table values, using the method specified as
the interpolation argument value |
Do not match the values in the input data sets, and are out of range | Extrapolates the output value, using the method specified as the
extrapolation argument value |
If the query input values x1
, x2
,
x3
, and x4
are:
Scalar, then the function returns a scalar.
N-D arrays, then the function returns an N-D array of the same size.
Error Checking
The following rules apply to data sets x1d
,
x2d
, x3d
, x4d
, and
fd
:
For one-dimensional table lookup,
x1d
andfd
must be one-dimensional arrays of the same size.For two-dimensional table lookup,
x1d
andx2d
must be one-dimensional arrays, andfd
must be a matrix, with the size matching the dimensions defined by the input data sets. For example, ifx1d
is a 1-by-m
array, andx2d
is a 1-by-n
array, thenfd
must be anm
-by-n
matrix.For three-dimensional table lookup,
x1d
,x2d
, andx3d
must be one-dimensional arrays, andfd
must be a three-dimensional array, with the size matching the dimensions defined by the input data sets. For example, ifx1d
is a 1-by-m
array,x2d
is a 1-by-n
array, andx3d
is a 1-by-p
array, thenfd
must be anm
-by-n
-by-p
array.For four-dimensional table lookup,
x1d
,x2d
,x3d
, andx4d
must be one-dimensional arrays, andfd
must be a four-dimensional array, with the size matching the dimensions defined by the input data sets. For example, ifx1d
is a 1-by-m
array,x2d
is a 1-by-n
array,x3d
is a 1-by-p
array, andx4d
is a 1-by-q
array, thenfd
must be anm
-by-n
-by-p
-by-q
array.The
x1d
,x2d
,x3d
, andx4d
values must be strictly monotonic, either increasing or decreasing.For smooth interpolation, each data set of input values must contain at least three values. For linear interpolation, two values are sufficient.
Using Enumerations for Interpolation and Extrapolation Options
The Foundation library includes built-in enumerations,
interpolation.m
and
extrapolation.m
:
classdef interpolation < int32 enumeration linear (1) smooth (2) end methods(Static) function map = displayText() map = containers.Map; map('linear') = 'Linear'; map('smooth') = 'Smooth'; end end end
classdef extrapolation < int32 enumeration linear (1) nearest (2) error (3) end methods(Static) function map = displayText() map = containers.Map; map('linear') = 'Linear'; map('nearest') = 'Nearest'; map('error') = 'Error'; end end end
These enumerations are located in the directory
matlabroot
\toolbox\physmod\simscape\library\m\+simscape\+enum
.
You can use these enumerations to declare component parameters, and then use these
parameters as tablelookup
function arguments.
For more information, see the User-Specified Interpolation and Extrapolation Methods example and
Using Enumeration in Function Arguments.
Examples
Version History
Introduced in R2012a