Direct Lookup Table (n-D)

Index into N-dimensional table to retrieve element, column, or 2-D matrix

Library

Lookup Tables

Description

Block Inputs and Outputs

The Direct Lookup Table (n-D) block uses inputs as zero-based indices into an n-dimensional table. The number of inputs varies with the shape of the output: an element, column, or 2-D matrix.

You define a set of output values as the Table data parameter. The first input specifies the zero-based index to the table dimension that is one higher than the output dimensionality. The next input specifies the zero-based index to the next table dimension, and so on.

Output ShapeOutput DimensionalityTable Dimension That Maps to the First Input
Element01
Column12
Matrix23

Suppose that you want to select a column of values from a 4-D table:

The following mapping of block input port to table dimension applies:

This input port...Is the index for this table dimension...
12
23
34

Changes in Block Icon Appearance

Depending on parameters you set, the block icon changes appearance. For table dimensions higher than 4, the icon matches the 4-D version but shows the exact number of dimensions in the top text.

When you use the Table data parameter, you see the following icons:

Object That Inputs Select from the TableNumber of Table Dimensions
1234

Element

Column

2-D Matrix

Not applicable

When you use the table input port, you see the following icons:

Object That Inputs Select from the TableNumber of Table Dimensions
1234

Element

Column

2-D Matrix

Not applicable

Data Type Support

The Direct Lookup Table (n-D) block accepts input signals of different data types.

Type of Input PortData Types Supported
Index port
  • Floating point

  • Built-in integer

  • Boolean

  • Enumerated data types

Table port (with the label T)
  • Floating point

  • Built-in integer

  • Fixed point

  • Boolean

  • Enumerated data types

The output data type is the same as the table data type. Inputs for indexing must be real, but table data can be complex.

When the table data is...The block inherits the output type from...
Not an inputThe Table data type parameter
An inputThe table input port

For more information, see Data Types Supported by Simulink in the Simulink® documentation.

Parameters and Dialog Box

Main tab

Number of table dimensions

Specify the number of dimensions that the Table data parameter must have. This value determines the number of independent variables for the table and the number of inputs to the block.

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.

Inputs select this object from table

Specify whether the output data is a single element, a column, or a 2-D matrix. The number of input ports for indexing depends on your selection.

SelectionNumber of Input Ports for Indexing
ElementNumber of table dimensions
ColumnNumber of table dimensions – 1
2-D MatrixNumber of table dimensions – 2

This numbering matches MATLAB® indexing. For example, if you have a 4-D table of data, follow these guidelines:

To access...Specify...As in...
An elementFour indicesarray(1,2,3,4)
A columnThree indicesarray(:,2,3,4)
A 2-D matrixTwo indicesarray(:,:,3,4)

Make table an input

Select this check box to force the Direct Lookup Table (n-D) block to ignore the Table data parameter. Instead, a new input port appears with T next to it. Use this port to input table data.

Table data

Specify the table of output values. The matrix size must match the dimensions of the Number of table dimensions parameter. The Table data field is available only if you clear the Make table an input check box.

    Tip   During block diagram editing, you can leave the Table data field empty. But for simulation, you must match the number of dimensions in Table data to the Number of table dimensions. For details on how to construct multidimensional MATLAB arrays, see Multidimensional Arrays in the MATLAB documentation.

Click Edit to open the Lookup Table Editor. For more information, see Edit Lookup Tables in the Simulink documentation.

Diagnostic for out-of-range input

Specify whether to show a warning or error when an index is out of range with respect to the table dimension. Options include:

  • None — do not display any 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 in the Diagnostic Viewer

When you select None or Warning, the block clamps out-of-range indices to fit table dimensions. For example, if the specified index is 5.3 and the maximum index for that table dimension is 4, the block clamps the index to 4.

Sample time (-1 for inherited)

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

Table Attributes tab

    Note:   The parameters in the Table Attributes pane are not available if you select Make table an input. In this case, the block inherits all table attributes from the input port with the label T.

Table minimum

Specify the minimum value for table data. The default value is [] (unspecified).

Table maximum

Specify the maximum value for table data. The default value is [] (unspecified).

Table data type

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

  • A rule that inherits a data type, for example, Inherit: Inherit from 'Table data'

  • 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 type parameter.

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 Lock the Output Data Type Setting in the Fixed-Point Designer™ documentation.

Examples

When Table Data Is Not an Input

Suppose that you have the following modelmodel:

The Direct Lookup Table (n-D) block parameters are:

Block ParameterValue
Number of table dimensions4
Inputs select this object from tableColumn
Make table an inputoff
Table dataa
Diagnostic for out-of-range inputWarning
Sample time–1
Table minimum[]
Table maximum[]
Table data typeint16
Lock data type settings against changes by the fixed-point toolsoff

In this example, a is a 4-D array of linearly increasing values that you define with the following model preload function:

a = reshape(1:2800, [4 5 20 7]);

When you run the model, you get the following results:

Because the Direct Lookup Table (n-D) block uses zero-based indexing, the output is:

a(:,2,4,3)

The output has the same data type as the table: int16.

When Table Data Is an Input

Suppose that you have the following modelmodel:

The Direct Lookup Table (n-D) block parameters are:

Block ParameterValue
Number of table dimensions4
Inputs select this object from tableColumn
Make table an inputon
Diagnostic for out-of-range inputWarning
Sample time–1

The key parameters of the Constant3 block are:

Block ParameterValue
Constant valuea
Output data typefixdt(1,16,2)

In this example, a is a 4-D array of linearly increasing values that you define with the following model preload function:

a = reshape(1:2800, [4 5 20 7]);

When you run the model, you get the following results:

The Constant3 block feeds the 4-D array to the Direct Lookup Table (n-D) block, using the fixed-point data type fixdt(1,16,2). Because the Direct Lookup Table (n-D) block uses zero-based indexing, the output is:

a(:,2,4,3)

The output has the same data type as the table: fixdt(1,16,2).

Characteristics

Direct Feedthrough

Yes

Sample Time

Specified in the Sample time parameter

Scalar Expansion

For scalar lookups only (not when returning a column or a 2-D matrix from the table)

Dimensionalized

For scalar lookups only (not when returning a column or a 2-D matrix from the table)

Multidimensionalized

Yes

Zero-Crossing Detection

No

Was this topic helpful?