2-D Lookup Table

Description

Supported Block Operations

The 1-D, 2-D, and n-D Lookup Table blocks evaluate a sampled representation of a function in N
variables

y=F(x1,x2,x3,...,xN)

where the function F can be empirical. The block maps inputs to an output
value by looking up or interpolating a table of values you define with block parameters. The
block supports flat (constant), linear (linear point-slope), Lagrange (linear Lagrange),
nearest, cubic-spline, and Akima spline interpolation methods. You can apply these methods to
a table of any dimension from 1 through 30.

In the following block, the first input identifies the first dimension (row) breakpoints, the second input identifies the second dimension (column) breakpoints, and so on.

When the Math and Data Types > Use algorithms optimized for row-major array layout configuration parameter is set, the 2-D and n-D Lookup Table block behavior
changes from column-major to row-major. For these blocks, the column-major and row-major
algorithms may differ in the order of the output calculations, possibly resulting in slightly
different numerical values. This capability requires a Simulink® Coder™ or Embedded
Coder® license. For more information on row-major support, see Code Generation of Matrices and Arrays (Simulink Coder).

Specification of Breakpoint and Table Data

These block parameters define the breakpoint and table data.

Block Parameter

Purpose

Number of table dimensions

Specifies the number of dimensions of your lookup table.

Breakpoints

Specifies a breakpoint vector that corresponds to each dimension of your lookup table.

How the Block Generates Output

The n-D, 1-D and 2-D Lookup Table blocks generate output by looking up or estimating table
values based on the input values.

Block Inputs

n-D Lookup Table Block Behavior

Match the values of indices in breakpoint data sets

Outputs the table value at the intersection of the row, column, and higher dimension breakpoints

Do not match the values of indices in breakpoint data sets, but are within range

Interpolates appropriate table values, using the Interpolation method
you select

Do not match the values of indices in breakpoint data sets, and are out of range

Extrapolates the output value, using the Extrapolation method you select

Other Blocks that Perform Equivalent Operations

You can use the Interpolation Using Prelookup block with the Prelookup block to perform the equivalent operation of one n-D Lookup Table block. This combination of blocks offers greater flexibility that can result in more efficient simulation performance for linear interpolations.

When the lookup operation is an array access that does not require interpolation, use the Direct Lookup Table (n-D) block. For example, if you have an integer value k and you want the kth element of a table, y = table(k), interpolation is unnecessary.

Parameters

Table and Breakpoints

Enter the number of dimensions of the lookup table. This parameter
determines:

The number of independent variables for the table and the
number of block inputs

The number of breakpoint sets to specify

To specify...

Do this...

1, 2, 3, or 4

Select the value from the drop-down list.

A higher number of table dimensions

Enter a positive integer directly in the
field.

The maximum number of table dimensions that this
block supports is 30.

For example, a table with a size of M x
N x ... means that the size of dimension 1 is
M, the size of dimension 2 is
N, and so forth. M must match
the first breakpoint length, N must match the second
breakpoint length, and so forth.

Table and breakpoints —
Specify the table data and breakpoints. Selecting this option
enables these parameters:

Table data

Breakpoints
specification

Breakpoints 1

Breakpoints 2

Edit table and
breakpoints

Lookup table object — Use an
existing lookup table (Simulink.LookupTable) object. Selecting this
option enables the Name field and
Edit table and breakpoints
button.

Programmatic Use

Block Parameter:DataSpecification

Type: character
vector

Values:'Table and breakpoints' | 'Lookup table
object'

Default:'Table and breakpoints'

Name — Name of the lookup table object[] (default) | Simulink.LookupTable object

Enter the name of the lookup table (Simulink.LookupTable) object. If a Simulink.LookupTable object does not exist,
click the action button and select
Create. The corresponding parameters of the
new lookup table object are automatically populated with the block
information.

Dependencies

To enable this parameter, set Data
specification to Lookup table
object.

During simulation, the matrix size must match the dimensions defined
by the Number of table dimensions parameter.
However, during block diagram editing, you can enter an empty matrix
(specified as []) or an undefined workspace variable.
This technique lets you postpone specifying a correctly dimensioned
matrix for the table data and continue editing the block diagram.

Dependencies

To enable this parameter, set Data
specification to Table and
breakpoints.

Specify whether to enter data as explicit breakpoints or as parameters
that generate evenly spaced breakpoints.

To explicitly specify breakpoint data, set this parameter to
Explicit values and enter
breakpoint data in the text box next to the
Breakpoints parameters.

To specify parameters that generate evenly spaced breakpoints,
set this parameter to Even spacing
and enter values for the First point and
Spacing parameters for each dimension
of breakpoint data. The block calculates the number of points to
generate from the table data.

Dependencies

To enable this parameter, set Data
specification to Table and
breakpoints.

Programmatic Use

Block Parameter:BreakpointsSpecification

Type: character
vector

Values:'Explicit values' | 'Even spacing'

Default:'Explicit values'

Breakpoints — Explicit breakpoint values, or first point and spacing of breakpoints[1:3] (default) | 1-by-n or n-by-1 vector of monotonically increasing values

Specify the breakpoint data explicitly or as evenly-spaced
breakpoints, based on the value of the Breakpoints
specification parameter.

If you set Breakpoints specification to
Explicit values, enter the
breakpoint set that corresponds to each dimension of table data
in each Breakpoints row. For each
dimension, specify breakpoints as a 1-by-n or n-by-1 vector
whose values are strictly monotonically increasing.

If you set Breakpoints specification to
Even spacing, enter the
parameters First point and
Spacing in each
Breakpoints row to generate
evenly-spaced breakpoints in the respective dimension. Your
table data determines the number of evenly spaced points.

Dependencies

To enable this parameter, set Data
specification to Table and
breakpoints.

Programmatic Use

Block Parameter:BreakpointsForDimension1

Type: character
vector

Values: 1-by-n or n-by-1
vector of monotonically increasing values

Default:'[1:3]'

First point — First point in evenly spaced breakpoint data1 (default) | scalar

Specify the first point in your evenly spaced breakpoint data as a
real-valued, finite, scalar. This parameter is available when
Breakpoints specification is set to
Even spacing.

Dependencies

To enable this parameter, set Data
specification to Table and
breakpoints, and Breakpoints
specification to Even
spacing.

If the extrapolation method is Linear, the
extrapolation value is calculated based on the selected linear interpolation
method. For example, if the interpolation method is linear Lagrange, the
extrapolation method inherits the linear Lagrange equation to compute the
extrapolated value.

Dependencies

To select Cubic spline for
Extrapolation method, you must also select
Cubic spline for
Interpolation method.

To select Akima spline for
Extrapolation method, you must also select
Akima spline for
Interpolation method.

This algorithm uses only the first two breakpoints of a set to determine the offset and spacing of the remaining points.

Note

Set Index search method to Evenly spaced points when using the Simulink.LookupTable object to specify table data and the Breakpoints Specification parameter of the referenced Simulink.LookupTable object is set to Even spacing.

For unevenly spaced breakpoint sets, follow these guidelines:

If input signals do not vary much between time steps, selecting Linear search with Begin index search using previous index result produces the best performance.

If input signals jump more than one or two table intervals per time step, selecting Binary search produces the best performance.

A suboptimal choice of index search method can lead to slow performance of models that rely heavily on lookup tables.

Note

The generated code stores only the first breakpoint, the spacing, and the number of breakpoints when:

The breakpoint data is not tunable.

The index search method is Evenly spaced points.

Programmatic Use

Block Parameter:IndexSearchMethod

Type: character vector

Values:'Binary search' | 'Evenly spaced points' | 'Linear search'

Default:'Binary search'

Begin index search using previous index result — Start using the index from the previous time stepoff (default) | on

Select this check box when you want the block to start its search using the index found at the previous time step. For inputs that change slowly with respect to the interval size, enabling this option can improve performance. Otherwise, the linear search and binary search methods can take longer, especially for large breakpoint sets.

Dependencies

To enable this parameter, set Index search method to Linear search or Binary search.

Specify whether to produce a warning or error when the input is out of range. Options include:

None — Produce no response.

Warning — Display a warning and continue the simulation.

Error — Terminate the simulation and display an error.

Programmatic Use

Block Parameter:DiagnosticForOutOfRangeInput

Type: character vector

Values:'None' | 'Warning' | 'Error'

Default:'None'

Use last table value for inputs at or above last breakpoint — Method for computing output for inputs at or above last breakpointoff (default) | on

Using this check box, specify the indexing convention that the block uses to address the last
element of a breakpoint set and its corresponding table value. This check box is
relevant if the input is equal to or larger than the last element of the
breakpoint data. Due to rounding, selecting and clearing this check box may
result in differing results for the last breakpoint between simulation and code
generation.

Check Box

Index Used by Block

Interval Fraction

Selected

Last element of breakpoint data on the Table and Breakpoints tab

0

Cleared

Next-to-last element of breakpoint data on the Table and Breakpoints tab

1

Given an input u within range of a breakpoint set bp,
the interval fraction f, in the range 0 f
1, is computed as shown below.

Suppose the breakpoint set is [1 4 5] and
input u is 5.5. If you select this check
box, the index is that of the last element (5) and the
interval fraction is 0. If you clear this check box, the index is that of the
next-to-last element (4) and the interval fraction is
1.

Dependencies

To enable this parameter, set:

Interpolation method to Linear.

Extrapolation method to Clip.

Programmatic Use

Block Parameter:UseLastTableValue

Type: character vector

Values:'off' | 'on'

Default:'off'

Input settings

Use one input port for all input data — Use only one input portoff (default) | on

Select this check box to use only one input port that expects a signal that is
n elements wide for an n-dimensional table. This option
is useful for removing line clutter on a block diagram with many lookup
tables.

Note

When you select this check box, one input port with the label
u appears on the block.

Code generation

Specify whether or not to include code that checks for out-of-range input
values.

Check Box

Result

When to Use

on

Generated code does not include conditional statements
to check for out-of-range breakpoint
inputs.

When the input is out-of-range, it may
cause undefined behavior for generated code.

For code efficiency

off

Generated code includes conditional statements to check
for out-of-range inputs.

For safety-critical applications

If your input is not out of range, you can select the Remove
protection against out-of-range index in generated code check box
for code efficiency. By default, this check box is cleared. For safety-critical
applications, do not select this check box. If you want to select the
Remove protection against out-of-range index in generated
code check box, first check that your model inputs are in range.
For example:

Additionally, to determine if it is safe to select this check box, if you have
a Simulink
Design Verifier™ license, consider using the Detect Block Input Range Violations (Simulink Design Verifier)
check.

Select this check box to enable tunable table size in the generated code. This
option enables you to change the size and values of the lookup table and
breakpoint data in the generated code without regenerating or recompiling the
code. You can only decrease the size of the lookup table and breakpoint
data.

Dependencies

If you set Interpolation method to Cubic
spline, this check box is not available.

Programmatic Use

Block Parameter:SupportTunableTableSize

Type: character vector

Values:'off' | 'on'

Default:'off'

Sample time — Specify sample time as a value other than -1-1 (default) | scalar | vector

Specify the sample time as a value other than -1. For more information, see Specify Sample Time.

Dependencies

To enable this parameter, select Support tunable table size in
code generation. On tuning this parameter in the generated
code, provide the new table data and breakpoints along with the tuned
parameter value.

Specify the data type for a set of breakpoint data. You can set it to:

A rule that inherits a data type, for example, Inherit: Same as corresponding input

The name of a built-in data type, for example, single

The name of a data type class, for example, an enumerated data type
class

The name of a data type object, for example, a Simulink.NumericType object

An expression that evaluates to a data type, for example, fixdt(1,16,0)

Tip

Breakpoints support unordered enumerated data. As a result, linear
searches are also unordered, which offers flexibility but can impact
performance. The search begins from the first element in the
breakpoint.

If the Begin index search using previous index
result check box is selected, you must use ordered
monotonically increasing data. This ordering improves
performance.

For enumerated data, Extrapolation method
must be Clip.

The block does not support out-of-range input for enumerated data.
When specifying enumerated data, include the entire enumeration set
in the breakpoint data set. For example, use the enumeration
function.

This is a limitation for using enumerated data with this block:

The block does not support out-of-range input for enumerated data.
When specifying enumerated data, include the entire enumeration set in
the breakpoint data set. For example, use the enumeration
function.

Specify the rounding mode for fixed-point lookup table calculations that occur during simulation or execution of code generated from the model. For more information, see Rounding (Fixed-Point Designer).

This option does not affect rounding of values of block parameters. Simulink rounds such values to the nearest representable integer value. To control the rounding of a block parameter, enter an expression using a MATLAB® rounding function into the edit field on the block dialog box.

Overflows wrap to the appropriate value that is representable by the data type.

The number 130 does not fit in a signed 8-bit integer and wraps to -126.

Tip

If you save your model as version R2009a or earlier, this check box setting has no effect and no saturation code appears. This behavior preserves backward compatibility.

When you select this check box, saturation applies to every internal operation on the block, not just the output or result. In general, the code generation process can detect when overflow is not possible. In this case, the code generator does not produce saturation code.

Block Characteristics

More About

Tunable Table Size in the Generated Code

Suppose that you have a lookup table and want to make the size tunable in the generated code. When you use Simulink.LookupTable and Simulink.Breakpoint objects to configure lookup table data for calibration in the generated code, use the SupportTunableSize property of the objects to enable a tunable table size. When you do not use these classes, use the Support tunable table size in code generation parameter in an n-D Lookup Table block to enable a tunable table size.

Assume that:

You define a Simulink.Parameter structure in the preload function of your model:

The highlighted line of code specifies a tunable table size for the lookup table. You can change the size and values of the lookup table and breakpoint data without regenerating or recompiling the code.

Enumerated Values in Lookup Tables

Suppose that you have a lookup table with an enumerated class like this defined:

This website uses cookies to improve your user experience, personalize content and ads, and analyze website traffic. By continuing to use this website, you consent to our use of cookies. Please see our Privacy Policy to learn more about cookies and how to change your settings.