Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Lookup Table (n-D) - Approximate N-dimensional function

Library

Lookup Tables

Description

How This Block Differs from Other Lookup Table Blocks

The Lookup Table (n-D) block evaluates a sampled representation of a function in N variables , 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, and cubic-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.

See How to Rotate a Block for a description of the port order for various block orientations.

Specification of Breakpoint and Table Data

The following block parameters define the breakpoint and table data.

Block ParameterPurpose
Number of table dimensionsSpecifies the number of dimensions of your lookup table.
Table and Breakpoints (BP) > BPSpecifies a breakpoint vector that corresponds to each dimension of your lookup table.
Table and Breakpoints (BP) > TableDefines the associated set of output values.

How the Block Generates Output

The Lookup Table (n-D) block generates output by looking up or estimating table values based on the input values:

If the inputs...The Lookup Table (n-D) block...
Match the values of indices in breakpoint data setsOutputs 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 rangeInterpolates appropriate table values, using the Interpolation method you select
Do not match the values of indices in breakpoint data sets, and are out of rangeExtrapolates 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 a Lookup Table (n-D) block. This combination of blocks offers greater flexibility that can result in more efficient simulation performance for linear interpolations in certain circumstances.

When the lookup operation is a simple 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.

Data Type Support

The Lookup Table (n-D) block supports all numeric data types supported by Simulink software, including fixed-point data types. For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink in the Simulink documentation.

Inputs for indexing must be real, but table data can be complex.

Parameters and Dialog Box

The Table and Breakpoints pane of the Lookup Table (n-D) block dialog box appears as follows:

Number of table dimensions

Enter the number of dimensions of the lookup table by specifying an integer from 1 to 30. This parameter determines:

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

  • The number of breakpoint sets to specify in Table and Breakpoints (BP)

Table and Breakpoints (BP)

In the Table row, enter the table of output values.

    Tip   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. For information about how to construct multidimensional arrays in MATLAB software, see Multidimensional Arrays in the MATLAB online documentation.

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

Edit table and breakpoints

Click this button to open the Lookup Table Editor. For more information, see Lookup Table Editor.

Sample time (-1 for inherited)

Specify the time interval between samples. To inherit the sample time, set this parameter to -1. See How to Specify the Sample Time for more information.

The Algorithm pane of the Lookup Table (n-D) block dialog box appears as follows:

Interpolation method

Select None - Flat, Linear (the default), or Cubic spline. See Interpolation Methods for more information.

    Tip   If you select Cubic spline, the block supports only scalar signals. The other interpolation methods support nonscalar signals.

Extrapolation method

Select None - Clip, Linear (the default), or Cubic spline. See Extrapolation Methods for more information.

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

Use last table value for inputs at or above last breakpoint

Specify the indexing convention that the block uses to address the last element of a breakpoint set and its corresponding table value.

Check Box SelectionIndex That the Block UsesInterval Fraction
YesThe last element of a breakpoint set0
NoThe next-to-last element of a breakpoint set1

This parameter is visible only when:

  • Interpolation method is Linear.

  • Extrapolation method is None - Clip.

Index search method

Select Evenly spaced points, Linear search, or Binary search (the default). Each search method has speed advantages in different circumstances:

  • For evenly spaced breakpoint sets (for example, 10, 20, 30, and so on), you achieve optimal speed by selecting Evenly spaced points to calculate table indices.

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

  • 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   Real-Time Workshop 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.

Begin index search using previous index result

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.

Use one input port for all input data

Instead of one input port per independent variable, 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.

Action for out-of-range input

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

  • None — the default, which means no warning or error message

  • Warning — display a warning message in the MATLAB Command Window and continue the simulation

  • Error — halt the simulation and display an error message in the Simulation Diagnostics Viewer

The Data Types pane of the Lookup Table (n-D) block dialog box appears as follows:

Table data

Specify the table data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Same as output

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

  • 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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Table data parameter.

    Tip   Specify a table data type different from the output data type for these cases:

    • Lower memory requirement for storing table data that uses a smaller type than the output signal

    • Sharing of prescaled table data between two Lookup Table (n-D) blocks with different output data types

    • Sharing of custom storage table data in Real-Time Workshop generated code for blocks with different output data types

Minimum (for Table data)

Specify the minimum value for table data. The default value, [], is equivalent to -Inf.

Maximum (for Table data)

Specify the maximum value for table data. The default value, [], is equivalent to Inf.

Breakpoints 1

Specify the data type for the first 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 object, for example, a Simulink.NumericType object

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

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Breakpoints 1 parameter.

See Using the Data Type Assistant for more information.

    Tip   Specify a breakpoint data type different from the corresponding input data type for these cases:

    • Lower memory requirement for storing breakpoint data that uses a smaller type than the input signal

    • Sharing of prescaled breakpoint data between two Lookup Table (n-D) blocks with different input data types

    • Sharing of custom storage breakpoint data in Real-Time Workshop generated code for blocks with different input data types

Minimum (for Breakpoints 1)

Specify the minimum value that the first set of breakpoint data can have. The default value, [], is equivalent to -Inf.

Maximum (for Breakpoints 1)

Specify the maximum value that the first set of breakpoint data can have. The default value, [], is equivalent to Inf.

Breakpoints 2

Specify the data type for the second 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 object, for example, a Simulink.NumericType object

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

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Breakpoints 2 parameter.

See Using the Data Type Assistant for more information.

    Tip   Specify a breakpoint data type different from the corresponding input data type for these cases:

    • Lower memory requirement for storing breakpoint data that uses a smaller type than the input signal

    • Sharing of prescaled breakpoint data between two Lookup Table (n-D) blocks with different input data types

    • Sharing of custom storage breakpoint data in Real-Time Workshop generated code for blocks with different input data types

Minimum (for Breakpoints 2)

Specify the minimum value that the second set of breakpoint data can have. The default value, [], is equivalent to -Inf.

Maximum (for Breakpoints 2)

Specify the maximum value that the second set of breakpoint data can have. The default value, [], is equivalent to Inf.

Fraction

Specify the fraction data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Inherit via internal rule

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

  • 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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Fraction parameter.

See Using the Data Type Assistant for more information.

Intermediate results

Specify the intermediate results data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Same as output

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

  • 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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Intermediate results parameter.

    Tip   Use this parameter to specify higher (or lower) precision for internal computations than for table data or output data.

Output

Specify the output data type. You can set it to:

  • A rule that inherits a data type, for example, Inherit: Inherit via back propagation

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

  • 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)

Click the Show data type assistant button to display the Data Type Assistant, which helps you set the Output parameter.

See Specifying Block Output Data Types for more information.

Minimum (for Output)

Specify the minimum value that the block outputs. The default value, [], is equivalent to -Inf. Simulink software uses this value to perform:

Maximum (for Output)

Specify the maximum value that the block outputs. The default value, [], is equivalent to Inf. Simulink software uses this value to perform:

Require all inputs to have the same data type

Select to require all inputs to have the same data type.

Lock data type settings against changes by the fixed-point tools

Select to lock all data type settings of this block against changes by the Fixed-Point Tool and the Fixed-Point Advisor. For more information, see Fixed-Point Tool and Fixed-Point Advisor in the Simulink Fixed Point documentation.

Integer rounding mode

Select 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 in the Simulink Fixed Point User's Guide.

This option does not affect rounding of values of block parameters. Simulink software 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.

Saturate on integer overflow

Select to have overflows saturate. Otherwise, they wrap.

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 which case, no saturation code is necessary.

    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.

Examples

For an example of entering breakpoint and table data, see Entering Data in a Block Parameter Dialog Box in the Simulink User's Guide.

For an example that illustrates linear interpolation and extrapolation methods of this block, see Example of a Logarithm Lookup Table in the Simulink User's Guide.

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

Yes

Dimensionalized

Yes, if you do not select Cubic spline for Interpolation method

Zero-Crossing Detection

No

See Also

Lookup Table Dynamic

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2010- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS