Index into n-dimensional table to retrieve element, vector, or 2-D matrix
expand all in page
Libraries:
Simulink / Lookup Tables
HDL Coder / Lookup Tables
Description
The Direct Lookup Table (n-D) block indexes into an n-dimensional table to retrieve anelement, vector, or 2-D matrix. The first selection index corresponds to the top (orleft) input port. You can choose to provide the table data as an input to the block, ordefine the table data on the block dialog box. The number of input ports and the size ofthe output depend on the number of table dimensions and the output slice youselect.
If you select a vector from a 2-D table, the output vector can be a column or a row,depending on the model configuration parameter setting Math and Data Types > Use algorithms optimized for row-major array layout. The block inputs are zero-based indices (for more information, see theInputs select this object from table parameter.
The Direct Lookup Table block supports symbolic dimensions.
Block Inputs and Outputs
The Direct Lookup Table (n-D) block uses inputs as zero-based indices into ann-dimensional table. The number of inputs varies with theshape of the output: an element, vector, or 2-D matrix.
You define a set of output values as the Table data parameter. For thedefault column-major algorithm behavior, the first input specifies the zero-basedindex to the table dimension that is one higher than the output dimensionality. Thenext input specifies the zero-based index to the next table dimension, and soon.
Output Shape | Output Dimensionality | Table Dimension that Maps to the First Input |
---|---|---|
Element | 0 | 1 |
Vector | 1 | 2 |
Matrix | 2 | 3 |
Suppose that you want to select a vector 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... |
---|---|
1 | 2 |
2 | 3 |
3 | 4 |
Changes in Block Icon Appearance
Depending on parameters you set, the block icon changes appearance. For table dimensionshigher than 4, the icon matches the 4-D version but shows the exact number ofdimensions at the top.
When you use the Table data parameter, you see these icons for thedefault column-major behavior. Some icons are different when you select theconfiguration parameter Math and Data Types > Use algorithms optimized for row-major array layout.
Object that Inputs Selectfrom the Table | Number of Table Dimensions | |||
---|---|---|---|---|
1 | 2 | 3 | 4 | |
Element | ||||
Vector | ||||
2-D Matrix | Not applicable |
When you use the table input port, you see these icons.
Object that Inputs Selectfrom the Table | Number of Table Dimensions | |||
---|---|---|---|---|
1 | 2 | 3 | 4 | |
Element | ||||
Vector | ||||
2-D Matrix | Not applicable |
Examples
expand all
Providing Table Data as an Input to the Direct Lookup Table Block
Open Model
This example shows how to provide table data as an input to the Direct Lookup Table block. In the following model, 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 block labeled TableData feeds a 4-D array to the Direct Lookup Table (n-D) block, with a data type of double. 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 data input signal: double.
Specifying Table Data in the Direct Lookup Table Block Dialog Box
Open Model
This example shows how to specify table data on the dialog box of the Direct Lookup Table (n-D) block. In the following model, the table data is 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 data type matches the Direct Lookup Table block's Table data type, which is set to int16
.
Ports
Input
expand all
Port_1 — Index i1
input values
scalar | vector
For the default column-major algorithm, the first input port, specifying the zero-basedindex to the table dimension that is one higher than the outputdimensionality (0, 1, or 2). The next input specifies the zero-basedindex to the next table dimension, and so on. All index inputs must bereal-valued.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Port_N — Index N
input values
scalar | vector
For the default column-major algorithm, the N-th input port,specifying the zero-based index to the table dimension that is N higherthan the output dimensionality (0, 1, or 2). The number of inputs varieswith the shape of the output. All index inputs must bereal-valued.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
T — Table data
vector | matrix | N-D array
Table data, specified as a vector, matrix, or N-D array. The table size must match thedimensions of the Number of dimensions parameter.The block's output data type is the same as the table data type.
Dependencies
To enable this port, select the Make table aninput check box.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Output
expand all
Port_1 — Output element, vector, or 2-D matrix
scalar | vector | 2-D matrix
Output slice, provided as a scalar, vector, or 2-D matrix. The size of the block outputis determined by the setting of the Inputs select this objectfrom table parameter. The output data type is the same asthe table data type.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| Boolean
| fixed point
| enumerated
Parameters
expand all
Main
Table
Number of table dimensions — Number of dimensions of table data
2
(default) | 1
| 3
| 4
Number of dimensions that the Table data parameter must have. Thisvalue determines the number of independent variables for the table andthe 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 thefield. The maximum number of table dimensions that thisblock supports is 30. |
Programmatic Use
Block Parameter:NumberOfTableDimensions |
Type: charactervector |
Values: '1' | '2' | '3' | '4' | ...|'30'| |
Default:'2' |
Make table an input — Provide table data as a block input
off
(default) | on
Select this check box to provide table data to the Direct Lookup Table(n-D) block as a block input. When you select this check box, a newinput port, T
, appears. Use this port to input thetable data.
Programmatic Use
Block Parameter:TableIsInput |
Type: charactervector |
Values: 'off' |'on' |
Default:'off' |
Table data — Table of output values
[4 5 6; 16 19 20; 10 18 23]
(default) | scalar, vector, matrix, or N-D array
Specify the table of output values. The table size must match thedimensions of the Number of table dimensionsparameter.
Tip
During block diagram editing, you can leave the Tabledata field empty. But for simulation, you must matchthe number of dimensions in Table data to theNumber of table dimensions. For details onhow to construct multidimensional MATLAB® arrays, see Multidimensional Arrays.
Click Edit to open the Lookup Table Editor. For more information,see Edit Lookup Tables.
Dependencies
To enable the Table data field, clear theMake table an input check box.
Programmatic Use
Block Parameter:Table |
Type: charactervector |
Values:scalar, vector, matrix, or N-D array |
Default:'[4 5 6;16 19 20;10 18 23]' |
Algorithm
Inputs select this object from table — Specify whether output is an element, vector, or 2-D matrix
Element
(default) | Vector
| 2-D Matrix
Specify whether the output data is a single element, a vector, or a2-D matrix. The number of input ports for indexing depends on yourselection.
Selection | Number of Input Ports forIndexing |
---|---|
Element | Number of table dimensions |
Vector | Number of table dimensions -1 |
2-D Matrix | Number 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 element | Four indices | array(1,2,3,4) |
A vector | Three indices | array(:,2,3,4) (default column-majoralgorithm) |
A 2-D matrix | Two indices | array(:,:,3,4) (default column-majoralgorithm) |
Tips
When the Math and Data Types > Use algorithms optimized for row-major arraylayout configuration parameter is set, the Direct LookupTable block behavior changes from column-major to row-major. Forthis block, the column-major and row-major algorithms may differsemantically in output calculations, resulting in differentnumerical values. For example, assume that Inputs selectthis object from table parameter is set toVector
. The elements of the selectedvector are contiguous in the table storage memory. This table showsthe column-major and row-major algorithm depending on the tabledimension:
Table Dimension | Column-Major Algorithm | Row-Major Algorithm |
---|---|---|
2-D table | Column vector is selected | Row vector is selected |
3-D and higher table | Output vector is selected from the firstdimension of the table | Output vector is selected from the last dimensionof the table |
Consider the row-major and column-major direct lookup algorithmswith vector output from a 3-D table. The last dimension is the thirddimension of a 3-D table. Due to semantic changes, column-major androw-major direct lookup may output different vector size andnumerical values.
This figure shows a Direct Lookup Table (n-D) block configured with a3-D table and a vector output. By default, the block icon shows thecolumn-major algorithm.
To have the same block use the row-major algorithm, change the Math and Data Types > Use algorithm optimized for row-majorlayout configuration parameter of the model and recompile.The block icon changes to reflect the change to the algorithmoptimized for row-major behavior.
For more information on row-major support, see Code Generation of Matrices and Arrays (Simulink Coder).
Programmatic Use
Block Parameter:InputsSelectThisObjectFromTable |
Type: charactervector |
Values:'Element' | 'Vector' | '2-D Matrix' |
Default:'Element' |
Diagnostic for out-of-range input — Block action when input is out of range
Warning
(default) | None
| Error
Specify whether to show a warning or error when an index is out ofrange with respect to the table dimension. Options include:
None
— Produce noresponse.Warning
— Display a warningand continue the simulation.Error
— Terminate thesimulation and display an error.
When you select None
orWarning
, the block clamps out-of-rangeindices to fit table dimensions. For example, if the specified index is5.3 and the maximum index for that table dimension is 4, the blockclamps the index to 4.
Programmatic Use
Block Parameter:DiagnosticForOutOfRangeInput |
Type: charactervector |
Values:'None' | 'Warning' | 'Error' |
Default:'Warning' |
Sample time (-1 for inherited) — Interval between samples
-1
(default) | scalar | vector
Specify the time interval between samples. To inherit the sample time, set this parameter to -1
. For more information, see Specify Sample Time.
Dependencies
This parameter is visible only if you set it to a value other than -1
. To learn more, see Blocks for Which Sample Time Is Not Recommended.
Programmatic Use
Block Parameter: SampleTime |
Type: string scalar or character vector |
Default: "-1" |
Code generation
Remove protection against out-of-range input in generated code — Remove code that checks for out-of-range input values
off
(default) | on
Specify whether or not to include code that checks for out-of-rangeinput values.
Check Box | Result | When to Use |
---|---|---|
| Generated code does not include conditional statements to check forout-of-range breakpoint inputs. When theinput is out-of-range, it may cause undefinedbehavior for generated code. | For code efficiency |
| Generated code includes conditional statementsto check for out-of-range inputs. | For safety-critical applications |
If your input is not out of range, you can select the Removeprotection against out-of-range index in generated codecheck box for code efficiency. By default, this check box is cleared.For safety-critical applications, do not select this check box. If youwant to select the Remove protection against out-of-rangeindex in generated code check box, first check that yourmodel inputs are in range. For example:
Clear the Remove protection against out-of-rangeindex in generated code check box.
Set the Diagnostic for out-of-range inputparameter to
Error
.Simulate the model in normal mode.
If there are out-of-range errors, fix them to be in range andrun the simulation again.
When the simulation no longer generates out-of-range inputerrors, select the Remove protection againstout-of-range index in generated code checkbox.
Note
When you select the Remove protection againstout-of-range index in generated code checkbox and the input is out of range, the behavior is undefinedfor generated code.
Depending on your application, you can run the following Model Advisorchecks to verify the usage of this check box:
By Product > Embedded Coder > Identify lookup table blocks that generateexpensive out-of-range checking code
By Product > Simulink Check > Modeling Standards > DO-178C/DO-331 Checks > Check usage of lookup tableblocks
For more information about the Model Advisor, see Run Model Advisor Checks.
Additionally, to determine if it is safe to select this check box, ifyou have a Simulink® Design Verifier™ license, consider using the Detect Block Input Range Violations (Simulink Design Verifier)check.
Programmatic Use
Block Parameter:RemoveProtectionInput |
Type: charactervector |
Values:'off' | 'on' |
Default:'off' |
Table Attributes
Note
The parameters in the Table Attributes pane are notavailable if you select Make table an input. In this case,the block inherits all table attributes from the input port with the labelT
.
Table minimum — Minimum value table data can have
[]
(default) | finite, real, double, scalar
Specify the minimum value for table data. The default value is[]
(unspecified).
Programmatic Use
Block Parameter:TableMin |
Type: charactervector |
Values: scalar |
Default:'[]' |
Table maximum — Maximum value table data can have
[]
(default) | finite, real, double, scalar
Specify the maximum value for table data. The default value is[]
(unspecified).
Programmatic Use
Block Parameter:TableMax |
Type: charactervector |
Values: scalar |
Default:'[]' |
Table data type — Data type of table data
Inherit: Inherit from 'Tabledata'
(default) | double
| single
| half
| int8
| uint8
| int16
| uint16
| int32
| uint32
| int64
| uint64
| boolean
| fixdt(1,16)
| fixdt(1,16,0)
| fixdt(1,16,2^0,0)
| Enum: <class name>
| <data type expression>
Specify the table data type. You can set it to:
A rule that inherits a data type, for example,
Inherit: Inherit from 'Tabledata'
The name of a built-in data type, for example,
single
The name of a data type class, for example, an enumerated datatype class
An expression that evaluates to a data type, for example,
fixdt(1,16,0)
The Data Type Assistant helps you set dataattributes. To use the Data Type Assistant, click . For more information, see Specify Data Types Using Data Type Assistant.
Programmatic Use
Block Parameter:TableDataTypeStr |
Type: charactervector |
Values:'Inherit: Inherit from 'Table data'' | 'double' |'single' | 'half' | 'int8' | 'uint8' | 'int16' | 'uint16' |'int32' | 'uint32' | 'int64' | 'uint64' | 'boolean' |'fixdt(1,16)' | 'fixdt(1,16,0)' | 'fixdt(1,16,2^0,0)'|'Enum:<class name>'|'<data typeexpression>' |
Default:'Inherit: Inherit from 'Table data'' |
Lock data type settings against changes by the fixed-point tools — Prevent fixed-point tools from overriding data types
off
(default) | on
Select this parameter to prevent the fixed-point tools from overriding the data types you specify on this block. For more information, see Lock the Output Data Type Setting (Fixed-Point Designer).
Programmatic Use
Block Parameter: LockScale |
Type: character vector |
Values: 'off' | 'on' |
Default: 'off' |
Block Characteristics
Data Types |
|
Direct Feedthrough |
|
Multidimensional Signals |
|
Variable-Size Signals |
|
Zero-Crossing Detection |
|
aThis block supports fixed-point data types for 'Table' data only. |
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.
HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.
HDL Coder™ provides additional configuration options that affect HDLimplementation and synthesized logic.
HDL Architecture
This block has one default HDL architecture.
HDL Block Properties
ConstrainedOutputPipeline | Number of registers to place at the outputs by moving existing delays within your design. Distributed pipelining does not redistribute these registers. The default is |
InputPipeline | Number of input pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is |
OutputPipeline | Number of output pipeline stages to insert in the generated code. Distributed pipelining and constrained output pipelining can move these registers. The default is |
Restrictions
MAX 10 Device Settings
If you use Intel® MAX 10 device, to map the lookup table to RAM, add this Tclcommand when creating the project in the Quartus tool:
set_global_assignment -name INTERNAL_FLASH_UPDATE_MODE "SINGLE IMAGEWITH ERAM"
Required Block Settings
Number of table dimensions: Select the tabledimension between 1 to 30.
Make table an input: Clear this checkbox.
Diagnostic for out-of-range input: Select
None
,Warning
(default), orError
(recommended). SelectError
for efficient HDL codegeneration. If you selectNone
orWarning
, HDL Coder generates additional logic to handle out-of-rangeinputs.
Table Data Typing and Sizing
It is good practice to size each dimension in the table to be apower of two. If the length of a dimension(except the innermost dimension) is not apower of two, HDL Coder issues a warning. By following this practice, you canavoid multiplications during table indexing operations and realize amore efficient table in hardware.
All ports on the block requirescalar values.
Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.
This block supports fixed-point data types for Table data only. Inaddition to built-in data types, the index input also supports fixed-point data typewith bias equal to 0, slope equal to 1.0, fractional length equal to 0, and wordlength less than or equal to 128.
Version History
Introduced before R2006a
See Also
n-D Lookup Table
Topics
- About Lookup Table Blocks
- Anatomy of a Lookup Table
- Enter Breakpoints and Table Data
- Guidelines for Choosing a Lookup Table
- Direct Lookup Table Algorithm for Row-Major Array Layout (Simulink Coder)
- Column-Major Layout to Row-Major Layout Conversion of Models with Lookup Table Blocks (Simulink Coder)
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office