Index into n-dimensional table to retrieve element, vector, or 2-D matrix (2024)

Table of Contents
Description Block Inputs and Outputs Changes in Block Icon Appearance Examples Providing Table Data as an Input to the Direct Lookup Table Block Specifying Table Data in the Direct Lookup Table Block Dialog Box Ports Input Port_1 — Index i1 input valuesscalar | vector Port_N — Index N input values scalar | vector T — Table data vector | matrix | N-D array Output Port_1 — Output element, vector, or 2-D matrixscalar | vector | 2-D matrix Parameters Main Number of table dimensions — Number of dimensions of table data2 (default) | 1 | 3 | 4 Make table an input — Provide table data as a block input off (default) | on Table data — Table of output values [4 5 6; 16 19 20; 10 18 23] (default) | scalar, vector, matrix, or N-D array Inputs select this object from table — Specify whether output is an element, vector, or 2-D matrix Element (default) | Vector | 2-D Matrix Diagnostic for out-of-range input — Block action when input is out of range Warning (default) | None | Error Sample time (-1 for inherited) — Interval between samples -1 (default) | scalar | vector Code generation Remove protection against out-of-range input in generated code — Remove code that checks for out-of-range input valuesoff (default) | on Table Attributes Table minimum — Minimum value table data can have [] (default) | finite, real, double, scalar Table maximum — Maximum value table data can have [] (default) | finite, real, double, scalar 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> Lock data type settings against changes by the fixed-point tools — Prevent fixed-point tools from overriding data types off (default) | on Block Characteristics Extended Capabilities C/C++ Code GenerationGenerate C and C++ code using Simulink® Coder™. HDL Code GenerationGenerate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™. Fixed-Point Conversion Design and simulate fixed-point systems using Fixed-Point Designer™. Version History See Also Topics MATLAB Command Americas Europe Asia Pacific References

Index into n-dimensional table to retrieve element, vector, or 2-D matrix

expand all in page

  • Index into n-dimensional table to retrieve element, vector, or 2-D matrix (1)

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 ShapeOutput DimensionalityTable Dimension that Maps to the First Input
Element01
Vector12
Matrix23

Suppose that you want to select a vector of values from a 4-D table.

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (2)

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 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 TableNumber of Table Dimensions
1234

Element

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (3)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (4)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (5)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (6)

Vector

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (7)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (8)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (9)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (10)

2-D Matrix

Not applicable

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (11)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (12)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (13)

When you use the table input port, you see these icons.

Object that Inputs Selectfrom the TableNumber of Table Dimensions
1234

Element

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (14)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (15)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (16)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (17)

Vector

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (18)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (19)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (20)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (21)

2-D Matrix

Not applicable

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (22)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (23)

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (24)

Examples

expand all

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:

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (25)

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.

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:

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (26)

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

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

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

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

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 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'

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'

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

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.

SelectionNumber of Input Ports forIndexing
ElementNumber of table dimensions
VectorNumber 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 vectorThree indicesarray(:,2,3,4) (default column-majoralgorithm)
A 2-D matrixTwo indicesarray(:,:,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 DimensionColumn-Major AlgorithmRow-Major Algorithm
2-D tableColumn vector is selectedRow vector is selected
3-D and higher tableOutput vector is selected from the firstdimension of the tableOutput 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.

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (27)

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.

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (28)

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'

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'

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

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

Check BoxResultWhen to Use

on

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

off

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:

  1. Clear the Remove protection against out-of-rangeindex in generated code check box.

  2. Set the Diagnostic for out-of-range inputparameter to Error.

  3. Simulate the model in normal mode.

  4. If there are out-of-range errors, fix them to be in range andrun the simulation again.

  5. 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.

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

Programmatic Use

Block Parameter:TableMin
Type: charactervector
Values: scalar
Default:'[]'

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

Programmatic Use

Block Parameter:TableMax
Type: charactervector
Values: scalar
Default:'[]'

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 Index into n-dimensional table to retrieve element, vector, or 2-D matrix (29). 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''

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

Boolean | double | enumerated | fixed pointa | half | integer | single

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

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™.

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.

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (30)

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)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Index into n-dimensional table to retrieve element, vector, or 2-D matrix (2024)

References

Top Articles
Latest Posts
Article information

Author: Dan Stracke

Last Updated:

Views: 6132

Rating: 4.2 / 5 (43 voted)

Reviews: 90% of readers found this page helpful

Author information

Name: Dan Stracke

Birthday: 1992-08-25

Address: 2253 Brown Springs, East Alla, OH 38634-0309

Phone: +398735162064

Job: Investor Government Associate

Hobby: Shopping, LARPing, Scrapbooking, Surfing, Slacklining, Dance, Glassblowing

Introduction: My name is Dan Stracke, I am a homely, gleaming, glamorous, inquisitive, homely, gorgeous, light person who loves writing and wants to share my knowledge and understanding with you.