Main Content

Simulink.LookupTable Class

Namespace: Simulink
Superclasses:

Store and share lookup table and breakpoint data, configure data for ASAP2 and AUTOSAR code generation

Description

An object of the Simulink.LookupTable class stores lookup table and breakpoint data. You can use that data in a lookup table block such as the n-D Lookup Table block. With the object, you can specify data types and code generation settings for the table and the breakpoint sets.

When you store all of the table and breakpoint set data in a single Simulink.LookupTable object, all of the data appears in a single structure in the generated code. To configure STD_AXIS code generation for calibration, use this technique.

To share a breakpoint set between multiple lookup tables, for example for COM_AXIS code generation, use a Simulink.Breakpoint object in one or more Prelookup blocks. Use Simulink.LookupTable objects in Interpolation Using Prelookup blocks. Then, configure the lookup table objects to refer to the breakpoint object. For more information, see Package Shared Breakpoint and Table Data for Lookup Tables.

To subclass from Simulink.LookupTable and inherit from this base class, type this syntax as the first line of your class definition file, where myLookuptable is the name of your new class:

classdef myLookuptable < Simulink.LookupTable

For an example on subclassing, see Define Data Classes.

If you add properties to the subclass, you can see them by displaying the subclass object at the MATLAB® command line. In the property dialog box, these properties display in a new tab.

Construction

LUTObj = Simulink.LookupTable returns a Simulink.LookupTable object LUTObj with default property values.

To create a Simulink.LookupTable object by using the Model Explorer, use the button on the toolbar. The default name for the object is Object.

Property Dialog Box

Setting Breakpoints specification to Explicit values (default) displays this view of the property dialog box.

The bottom of the dialog box contains the table and breakpoint data values. For more information on this tabular area, see Edit Lookup Table Data with Lookup Table Spreadsheet. The contents of this table are equivalent to the Value property, visible when the Breakpoints specification property is set to Even spacing or Reference.

Table and Breakpoints

Number of table dimensions

Number of dimensions of the lookup table. Specify an integer value up to 30 (inclusive). For example, to represent a three-dimensional lookup table, specify the integer 3.

, Breakpoints specification

Source for the information of the breakpoint sets, specified as Explicit values (default), Reference, or Even spacing.

  • To store all of the table and breakpoint set data in the Simulink.LookupTable object, set Breakpoints specification to Explicit values.

    The Simulink.LookupTable object appears in the generated code as a single structure variable.

  • To store the table data in the Simulink.LookupTable object and store the breakpoint set data in Simulink.Breakpoint objects, set Breakpoints specification to Reference.

    The Simulink.LookupTable object appears in the generated code as a separate array variable that contains the table data. Each Simulink.Breakpoint object appears as a separate array or structure variable that contains the breakpoint set data.

  • To store the table data and evenly spaced breakpoints in the Simulink.LookupTable object, set Breakpoints specification to Even spacing. Use the First point and Spacing parameters to generate a set of evenly spaced breakpoints.

Note

When Breakpoints specification is set to Explicit values or Even spacing, you can change the order of the tunable size, breakpoint, and table entries in a lookup table object-generated structure.

Table

Information for the table data. You can configure these characteristics:

Value

Table data. Specify a numeric vector or multidimensional array with at least two elements.

The Value table data is the same as the contents of the tabular interface visible at the bottom of the dialog box when the Breakpoints specification property is set to Explicit values. For more information on this tabular area, see Edit Lookup Table Data with Lookup Table Spreadsheet.

Note

This property appears only if Breakpoints specification is set to Even spacing or Reference.

Lookup Table property dialog box with Breakpoints specification set to Even spacing.

You can also use an expression with mathematical operators such as sin(1:0.5:30) as long as the expression returns a numeric vector or multidimensional array. When you click Apply or OK, the object executes the expression and uses the result to set the value of this property.

When you set Data type to auto, to set Value, use a typed expression such as single([1 2 3]) or use the fi (Fixed-Point Designer) constructor to embed an fi object.

When you specify table data with three or more dimensions, Value displays the data as an expression that contains a call to the reshape function. To edit the values in the data, modify the first argument of the reshape call, which contains all of the values in a serialized vector. When you add or remove elements along a dimension, you must also correct the argument that represents the length of the modified dimension.

You can edit this data by using a more intuitive interface in a lookup table block. See Import Lookup Table Data from MATLAB.

Data type

Data type of the table data. The default setting is auto, which means that the table data acquire a data type from the value that you specify in Value. If you use an untyped expression such as [1 2 3] to set Value, the table data use the data type double. If you specify a typed expression such as single([1 2 3]) or an fi object, the table data use the data type specified by the expression or object. Enumerated data types are also supported.

You can explicitly specify an integer data type, half data type, a floating-point data type, a fixed-point data type, or a data type expression such as the name of a Simulink.AliasType object.

For more information about data types in Simulink®, see Data Types Supported by Simulink. To decide how to control the data types of table and breakpoint data in Simulink.LookupTable and Simulink.Breakpoint objects, see Control Data Types of Lookup Table Objects (Simulink Coder).

Dimensions

Dimension lengths of the lookup table data.

To use symbolic dimensions, specify a character vector. See Implement Symbolic Dimensions for Array Sizes in Generated Code (Embedded Coder).

Min

Minimum value of the elements in the table data. The default value is empty, []. You can specify a numeric, real value.

For more information about how Simulink uses this property, see Specify Minimum and Maximum Values for Block Parameters.

Max

Maximum value of the elements in the table data. The default value is empty, []. You can specify a numeric, real value.

For more information about how Simulink uses this property, see Specify Minimum and Maximum Values for Block Parameters.

Stored Int Min

For Simulink.LookupTable objects with a fixed-point data type, the minimum value of the elements in the table data, specified as a stored integer value. The value is derived from the real-world value Min. This property is available only in the property dialog box.

Stored Int Max

For Simulink.LookupTable objects with a fixed-point data type, the maximum value of the elements in the table data, specified as a stored integer value. The value is derived from the real-world value Max. This property is available only in the property dialog box.

Unit

Physical units of the elements in the lookup table. You can specify text such as degC. See Unit Specification in Simulink Models.

Field name

Name of a structure field in the generated code. This field stores the table data if you configure the Simulink.LookupTable object to appear in the generated code as a structure. The default value is Table. To change the field name, specify text.

Description

Description of the lookup table. You can specify text such as This lookup table describes the action of a pump.

Breakpoints

Breakpoint set information. Each row is one breakpoint set. To configure additional breakpoint sets, specify an integer value in the Number of table dimensions box.

For the breakpoint sets, you can configure these characteristics:

Value

Data for the breakpoint set. Specify a numeric vector with at least two elements.

Note

This property appears only if Breakpoints specification is set to Even spacing or Reference. The Value breakpoint set data is the same as the contents of the tabular interface visible at the bottom of the dialog box when the Breakpoints specification property is set to Explicit values. For more information on this tabular area, see Edit Lookup Table Data with Lookup Table Spreadsheet.

You can also use an expression with mathematical operators such as sin(1:0.5:30) as long as the expression returns a numeric vector. When you click Apply or OK, the object executes the expression and uses the result to set the value of this property.

When you set Data type to auto, to set Value, use a typed expression such as single([1 2 3]) or use the fi (Fixed-Point Designer) constructor to embed an fi object.

You can edit this data by using a more intuitive interface in a lookup table block. See Import Lookup Table Data from MATLAB.

Data type

Data type of the breakpoint set. The default setting is auto, which means that the breakpoint set acquires a data type from the value that you specify in Value. If you use an untyped expression such as [1 2 3] to set Value, the breakpoint data use the data type double. If you specify a typed expression such as single([1 2 3]) or an fi object, the breakpoint data use the data type specified by the expression or object.

You can explicitly specify an integer data type, a floating-point data type, a fixed-point data type, or a data type expression such as the name of a Simulink.AliasType object.

For more information about data types in Simulink, see Data Types Supported by Simulink. To decide how to control the data types of table and breakpoint data in Simulink.LookupTable and Simulink.Breakpoint objects, see Control Data Types of Lookup Table Objects (Simulink Coder).

Dimensions

Dimension lengths of the breakpoint set.

To use symbolic dimensions, specify a character vector. See Implement Symbolic Dimensions for Array Sizes in Generated Code (Embedded Coder).

Min

Minimum value of the elements in the breakpoint set. The default value is empty, []. You can specify a numeric, real value.

For more information about how Simulink uses this property, see Specify Minimum and Maximum Values for Block Parameters.

Max

Maximum value of the elements in the breakpoint set. The default value is empty, []. You can specify a numeric, real value.

For more information about how Simulink uses this property, see Specify Minimum and Maximum Values for Block Parameters.

Unit

Physical unit of the elements in the breakpoint set. You can specify text such as degF. See Unit Specification in Simulink Models.

Field name

Name of a structure field in the generated code. This field stores the breakpoint set data. The default value is BP1 for the first breakpoint set and BP2 for the second set. To change the field name, specify text.

Tunable size name

Name of a structure field in the generated code. This field stores the length (number of elements) of the breakpoint set, which the generated code algorithm uses to determine the size of the table. To tune the effective size of the table during code execution, change the value of this structure field in memory. The default name is N1 for the first breakpoint set and N2 for the second set. To change the field name, specify text.

This column appears only if you select Support tunable size.

Description

Description of the breakpoint set. You can specify text such as This breakpoint set represents the pressure input.

First point

First point in evenly spaced breakpoint data. This parameter is available when Breakpoints specification is set to Even spacing.

Spacing

Spacing between points in evenly spaced breakpoint data. This parameter is available when Breakpoints specification is set to Even spacing.

Name

Name of the Simulink.Breakpoint object that stores the information for this breakpoint set.

This column appears only if you set Breakpoints specification to Reference.

First point name

Name of the Simulink.Breakpoint object that stores the information for the first point. This parameter is available when Breakpoints specification is set to Even spacing.

Spacing name

Name of the Simulink.Breakpoint object that stores the information for the spacing. This parameter is available when Breakpoints specification is set to Even spacing.

Table and breakpoint value edit area

Information for table and breakpoint data. You can enter a MATLAB expression in the associated text box or add data directly in the accompanying table. Select the desired data type:

  • Select table elements

  • Use standard keyboard shortcuts such as:

    • Copy — Ctrl+C

    • Paste — Ctrl+V

    • Undo — Ctrl+Z

    • Delete

    • Redo — Shift+Ctrl+Z

Entering or manipulating data in the table is simple and intuitive. Like Microsoft® Excel® spreadsheets, you can work with the table with operations such as:

  • Table — Table data. Specify a numeric vector or multidimensional array with at least two elements.

    You can also use an expression with mathematical operators such as sin(1:0.5:30) as long as the expression returns a numeric vector or multidimensional array. When you press Enter, the object executes the expression and uses the result to set the value of this property.

    When you specify table data with three or more dimensions, the table displays the data as an expression that contains a call to the reshape function. To edit the values in the data, modify the first argument of the reshape call, which contains all of the values in a serialized vector. When you add or remove elements along a dimension, you must also correct the argument that represents the length of the modified dimension.

    You can edit this data using a more intuitive interface in a lookup table block. See Import Lookup Table Data from MATLAB.

  • BPN — Data for the breakpoint set.

    Specify a numeric vector with at least two elements.

    You can also use an expression with mathematical operators such as sin(1:0.5:30) as long as the expression returns a numeric vector. When you press Enter, the object executes the expression and uses the result to set the value of this property.

    You can edit this data by using a more intuitive interface in a lookup table block. See Import Lookup Table Data from MATLAB.

Code Generation

Data definition: Storage class

Storage class of the structure variable (if you set Breakpoints specification to Explicit values or Even spacing) or array variable (Reference) in the generated code. The variable stores the table data and, if the variable is a structure, the breakpoint set data. The default setting is Auto.

For more information about storage classes, see C Data Code Interface Configuration for Model Interface Elements (Simulink Coder).

If you have Embedded Coder®, you can choose a custom storage class. For information about custom storage classes, see Organize Parameter Data into a Structure by Using Struct Storage Class (Embedded Coder).

Data definition: Identifier

Alternative name for the structure variable (if you set Breakpoints specification to Explicit values or Even spacing) or array variable (Reference) in the generated code. The default value is empty, in which case the generated code uses the name of the Simulink.LookupTable object as the name of the structure or array variable. To set the identifier, specify text.

To enable this property, set Data definition: Storage class to a setting other than Auto.

Data definition: Alignment

Data alignment boundary in the generated code. The starting memory address for the data allocated for the structure or array variable is a multiple of the value that you specify. The default value is -1, which allows the code generator to determine an optimal alignment based on usage.

Specify a positive integer that is a power of 2. For more information about using data alignment for code replacement, see Data Alignment for Code Replacement (Embedded Coder).

Before R2024a: Specify a value not exceeding 128.

Struct Type definition: Name

Name of the structure type that the structure variable uses in the generated code. The default value is empty. Specify text.

This property appears only if you set Breakpoints specification to Explicit values or Even spacing.

Struct Type definition: Data scope

Scope of the structure type definition (imported from your custom code or exported from the generated code). The default value is Auto. When you select Auto:

  • If you do not specify a value in the Struct Type definition: Header file box, the generated code exports the structure type definition to the file model_types.h. model is the name of the model.

  • If you specify a value in the Struct Type definition: Header file box, such as myHdr.h, the generated code imports the structure type definition from myHdr.h.

To explicitly specify the data scope:

  • To import the structure type definition into the generated code from your custom code, select Imported.

  • To export the structure type definition from the generated code, select Exported.

Set the data scope of the structure type definition to Imported or Exported to avoid potential MISRA C:2012 violations.

If you do not specify a value in the Struct Type definition: Header file box, the generated code imports or exports the type definition from or to StructName.h. StructName is the name that you specify by using the property Struct Type definition: Name.

This property appears only if you set Breakpoints specification to Explicit values or Even spacing.

Struct Type definition: Header file

Name of the header file that contains the structure type definition. You can import the definition from a header file that you create, or export the definition into a generated header file. To control the scope of the structure type, adjust the setting for the Struct Type definition: Data scope property.

This property appears only if you set Breakpoints specification to Explicit values or Even spacing.

Advanced

Support tunable size

Specification to enable tuning the effective size of the table in simulation and the generated code. In the code, the structure that corresponds to the object has an extra field for each breakpoint vector. Each extra field stores the length of the corresponding breakpoint vector. You can change the value of each field to adjust the effective size of the table. For more information on breakpoint and table sizes, see Breakpoint and Table Size Features in Lookup Tables.

This property appears only if you set Breakpoints specification to Explicit values or Even spacing. Selecting Allow multiple instances of this type to have different table and breakpoint sizes automatically selects this property.

Note

If you store breakpoint data in Simulink.Breakpoint objects by setting Breakpoints specification to Reference, to enable tuning of the table size in the generated code, use the Support tunable size property of each Simulink.Breakpoint object.

Allow multiple instances of this type to have different table and breakpoint sizes

Specification to configure a Lookup Table object to support differently sized tables and breakpoints that have the same structure type. For example, assume two 1-D lookup table objects are configured as shown and have the same struct type name.

  • Lookup table with tables and breakpoints of size [1x4]

  • Lookup table with tables and breakpoints of size [1x6]

To enable a model with two blocks containing these objects to simulate, select the Allow multiple instances of this type to have different table and breakpoint sizes check box. For code generation with Simulink Coder™, the software generates a common struct type with pointer typed member fields for the two objects to represent the table and breakpoint data.

This property appears only if you set Breakpoints specification to Explicit values or Even spacing.

For more information on breakpoint and table sizes, see Breakpoint and Table Size Features in Lookup Tables.

Properties

expand all

Breakpoint set information, specified as a vector of Simulink.lookuptable.Breakpoint objects, a cell array of character vectors, or a vector of Simulink.lookuptable.Evenspacing objects.

If you use a vector of Simulink.lookuptable.Breakpoint objects, each object represents a breakpoint set. To use a vector of Simulink.lookuptable.Breakpoint objects, set the property BreakpointsSpecification to 'Explicit values'.

If you use a cell array of character vectors, each character vector represents the name of a Simulink.Breakpoint object. To use a cell array of character vectors, set the property BreakpointsSpecification to 'Reference'.

If you use a vector of Simulink.lookuptable.Evenspacing objects, each object represents a breakpoint set. To use a vector of Simulink.lookuptable.Evenspacing objects, set the property BreakpointsSpecification to 'Even Spacing'.

Source of the breakpoint set information, specified as 'Explicit values' (default), 'Even spacing', or 'Reference'. See the Breakpoints > Specification parameter.

Data Types: char

Code generation settings for the structure variable (if you set BreakpointsSpecification to 'Explicit values' or 'Even spacing') or array variable ('Reference') that stores the lookup table and breakpoint sets, specified as a Simulink.CoderInfo object. You can specify a storage class or custom storage class by using this embedded object. See Simulink.CoderInfo.

Settings for the structure type that the structure variable uses in the generated code, specified as a Simulink.lookuptable.StructTypeInfo object.

If you set BreakpointsSpecification to 'Reference', the Simulink.LookupTable object does not appear in the generated code as a structure. The code generator ignores this property.

Option to simulate or generate code that enables tunability of the effective size of the table, specified as true or false. See the Support Tunable Size parameter.

Data Types: logical

Information for the table data, specified as a Simulink.lookuptable.Table object.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.

Examples

Represent a One-Dimensional Lookup Table

  1. Create a Simulink.LookupTable object named LUTObj.

    LUTObj = Simulink.LookupTable;

  2. Specify the table data.

    LUTObj.Table.Value = [1.1 2.2 3.3 4.4 5.5];

  3. Specify the breakpoint set data.

    LUTObj.Breakpoints(1).Value = [-2 -1 0 1 2];

  4. Specify a name for the structure type in the generated code.

    LUTObj.StructTypeInfo.Name = 'myLUTStruct';

You can use LUTObj in a 1-D Lookup Table block dialog box. In the block, set Data specification to Lookup table object and Name to LUTObj.

To view the data, use the property dialog as described in Edit Lookup Table Data with Lookup Table Spreadsheet.

Represent a Two-Dimensional Lookup Table

  1. Create a Simulink.LookupTable object named LUTObj.

    LUTObj = Simulink.LookupTable;

  2. Specify the table data.

    LUTObj.Table.Value = [1.1 2.2 3.3 4.4 5.5; ...
                              6.6 7.7 8.8 9.9 10.1];

  3. Specify the breakpoint set data. In the Breakpoints property, use the vector index 2 to set the values in the second breakpoint set.

    LUTObj.Breakpoints(1).Value = [-1 1];
    
    LUTObj.Breakpoints(2).Value = [-2 -1 0 1 2];
    

    LUTObj creates a Simulink.lookuptable.Breakpoint object as the second vector element in the value of the Breakpoints property. Except for the Value property, the new object has default property values.

  4. Specify a name for the structure type in the generated code.

    LUTObj.StructTypeInfo.Name = 'myLUTStruct';

You can use LUTObj in a 2-D Lookup Table block dialog box.

To view the data, use the property dialog as described in Edit Lookup Table Data with Lookup Table Spreadsheet.

Evenly Space Every Second Value Starting from 1

To evenly space every second value starting from 1, use the Breakpoint object.

  1. Create a Simulink.LookupTable object named LUTObj.

    LUTObj=Simulink.LookupTable
    
    LUTObj = 
    
      LookupTable with properties:
    
                           Table: [1×1 Simulink.lookuptable.Table]
        BreakpointsSpecification: 'Explicit values'
                     Breakpoints: [1×1 Simulink.lookuptable.Breakpoint]
              SupportTunableSize: 0
                       CoderInfo: [1×1 Simulink.CoderInfo]
                  StructTypeInfo: [1×1 Simulink.lookuptable.StructTypeInfo]
  2. Set up the breakpoint property to even spacing.

    LUTObj.BreakpointsSpecification='Even spacing'
    
    LUTObj = 
    
      LookupTable with properties:
    
                           Table: [1×1 Simulink.lookuptable.Table]
        BreakpointsSpecification: 'Even spacing'
                     Breakpoints: [1×1 Simulink.lookuptable.Evenspacing]
              SupportTunableSize: 0
                       CoderInfo: [1×1 Simulink.CoderInfo]
                  StructTypeInfo: [1×1 Simulink.lookuptable.StructTypeInfo]
  3. Get the properties of the breakpoint.

    LUTObj.Breakpoints(1)
    
    
    ans = 
    
      Evenspacing with properties:
    
             FirstPoint: 0
                Spacing: 1
               DataType: 'auto'
                    Min: []
                    Max: []
                   Unit: ''
         FirstPointName: 'BPFirstPoint1'
            SpacingName: 'BPSpacing1'
        TunableSizeName: 'N1'
            Description: ''
  4. To set the first point property, use the Breakpoint object FirstPoint property.

    LUTObj.Breakpoints(1).FirstPoint=1
  5. To set the spacing property, use the Breakpoint object.

    LUTObj.Breakpoints(1).Spacing=2
  6. Get the properties of the breakpoint.

    LUTObj.Breakpoints(1)
    
    ans = 
    
      Evenspacing with properties:
    
             FirstPoint: 1
                Spacing: 2
               DataType: 'auto'
                    Min: []
                    Max: []
                   Unit: ''
         FirstPointName: 'BPFirstPoint1'
            SpacingName: 'BPSpacing1'
        TunableSizeName: 'N1'
            Description: ''

Limitations

When blocks in a subsystem use Simulink.LookupTable or Simulink.Breakpoint objects, you cannot set data type override only on the subsystem. Instead, set data type override on the entire model.

Version History

Introduced in R2016b

expand all