Main Content

Breakpoint and Table Size Features in Lookup Tables

Simulink® supports multiple size related features in lookup tables. This topic summarizes these features and describes when to use them.

Tunable Size

Lookup tables consist of breakpoint and table arrays that lookup table blocks use to look up inputs and interpolate table data. These arrays have fixed sizes once the simulation starts. They appear as arrays in generated C/C++ code. Tunable sizes enable you to work with a smaller range of active breakpoints, also known as active region, within the larger fixed size of the breakpoint array. Use tunable sizes when you need to tune or calibrate your lookup table without needing to resize the arrays and regenerate code. With this feature, the generated C/C++ code includes a tunable size variable, whose value you can change, between compile runs or during program execution by writing into its memory location. As of R2022b, this feature is available only in code generation. To use the tunable size feature, select the Support tunable size check box on the Advanced tab of the Simulink.LookupTable property dialog box.

In this example, the breakpoint array of the lookup table is of size 10. N denotes the tunable size.

Active region of size 6 representing active breakpoints in larger fixed size 10 of breakpoint array.

Symbolic Dimensions

Symbolic dimensions let you create breakpoint and table arrays using sizes represented by symbolic values in simulation and generated C/C++ code. Symbolic dimensions allow you to easily change the size of your lookup table data between compile runs. In generated C/C++ code, these symbolic values appear as macros used to declare the breakpoint and table C arrays. The symbolic values represent the larger fixed sizes of the breakpoints and table. Use the tunable size feature with symbolic dimensions to choose a smaller active region within the symbolic size in the generated C/C++ code. To use symbolic dimensions, see the Dimensions parameter on the Table and Breakpoints tab of the Simulink.LookupTable property dialog box.

In this example, the breakpoint and table arrays of the lookup table are of size S. S is a macro that can represent different sizes between compile runs.

S is a macro that can represent different sizes (6, 8, and 5) between compile runs.

Reusable Struct Data Types for Different Breakpoint and Table Array Sizes

Simulink.LookupTable objects let you create struct data types with fields to represent breakpoint and table data. Lookup table objects also provide for customization of the struct data type definition. The reusable struct data types feature lets you use the same struct data type to represent multiple lookup table objects, each with different lookup table array sizes.

In simulation, you can have multiple n-D Lookup Table blocks, each with objects having different table and breakpoint sizes with the same struct data type name. You can also pass these differently sized array objects via model arguments in a model reference hierarchy, setting up a size-independent interface between models for your lookup table data types. In the generated C/C++ code, the struct data type represents the breakpoint and table fields as pointer data types instead of array data types.

Without this feature, achieving the same behavior requires padding the differently sized arrays to the maximum size of the arrays of the participating lookup table objects. Padding in this manner has several disadvantages, such as wasted memory and slower breakpoint search speed.

Starting in R2022b, to work with different breakpoint and table array sizes, use the Allow multiple instances of this type to have different table and breakpoint sizes check box on the Advanced tab of the Simulink.LookupTable property dialog box.

As an example, the Two Lookup Table Objects with Differently Sized Arrays graphic shows two lookup table objects, each with different breakpoint and table array sizes.

  • LUT object 1 has breakpoint and table arrays of size [1x4].

  • LUT object 2 has breakpoint and table arrays of size [1x6].

We would like to have the same struct data type, lookup_type, represent both objects. As presented, the configuration issues an error during model update diagram.

Two Lookup Table Objects with Differently Sized Arrays

Two lookup table objects, each having different breakpoint and table array sizes. LUT object 1 has breakpoint and table arrays of size [1x4]. LUT object 2 has breakpoint and table arrays of size [1x6].

To resolve the sizing discrepancy, in releases before R2022b, the workaround was to use padding to match the array sizes of the participating lookup table objects. This approach is not optimal.

The Lookup Table Object with Padding Applied graphic shows the padding workaround. Breakpoint and table arrays of LUT object 1 are padded to match the size of the breakpoint and table arrays of LUT object 2. Notice how the struct data type, lookup_type, generated in the C/C++ code, has breakpoint and table fields as arrays of size 6. With this, the struct data type can represent both LUT object 1 and LUT object 2 using padding.

Lookup Table Object with Padding Applied

Two lookup tables, where the table array of size [1x4] has padding applied.

Starting in R2022b, to solve the size discrepancy, use the Allow multiple instances of this type to have different table and breakpoint sizes check box in the Simulink.LookupTable object. This feature allows the same struct data type to represent different breakpoint and table sizes.

The Lookup Table Object with Differently Sized Tables and Breakpoints Enabled graphic shows the same lookup table object configuration, but with the Allow multiple instances of this type to have different table and breakpoint sizes check box selected. The struct data type, lookup_type, in the generated C/C++ code, has breakpoint and table fields as pointers instead of arrays. As a result, the struct data type can represent LUT object 1 and LUT object 2 without requiring any padding.

Lookup Table Object with Differently Sized Tables and Breakpoints Enabled

Lookup table with Allow multiple instances of this type to have different table and breakpoint sizes parameter selected.

See Also

| | |

Related Topics