Package: Simulink
Superclasses:
Store and share lookup table and breakpoint data, configure the data for ASAP2 and AUTOSAR code generation
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.
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
.
Setting Breakpoints specification to
Explicit
(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 View Simulink.LookupTable Object Data Using the Property Dialog Box Tabular Interface. The contents of
this table are equivalent to the Value property, visible when the
Breakpoints specification property is set to Even
spacing
or Reference
.
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
.
Information for the table data. You can configure these characteristics:
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
. For more
information on this tabular area, see View Simulink.LookupTable Object Data Using the Property Dialog Box Tabular Interface.
Note
This property appears only if Breakpoints
specification is set to Even
spacing
or
Reference
.
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 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).
Dimension lengths of the lookup table data.
To use symbolic dimensions, specify a character vector. See Implement Dimension Variants for Array Sizes in Generated Code (Embedded Coder).
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.
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.
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.
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.
Physical units of the elements in the lookup table. You can
specify text such as degC
. See Unit Specification in Simulink Models.
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 of the lookup table. You can specify text such as This
lookup table describes the action of a pump
.
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:
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
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
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
Specification to
Even spacing
. Use the
First point and
Spacing parameters to
generate a set of evenly spaced breakpoints.
Note
When 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.
Specification to enable tuning the effective size of the table in 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.
This property appears only if you set
Specification to
Explicit values
or
Even spacing
.
Note
If you store breakpoint data in Simulink.Breakpoint
objects by setting
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.
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
.
For more information on this tabular area, see View Simulink.LookupTable Object Data Using the Property Dialog Box Tabular Interface.
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 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).
Dimension lengths of the breakpoint set.
To use symbolic dimensions, specify a character vector. See Implement Dimension Variants for Array Sizes in Generated Code (Embedded Coder).
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.
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.
Physical unit of the elements in the
breakpoint set. You can specify text such as
degF
. See Unit Specification in Simulink Models.
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.
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 of the breakpoint set. You can
specify text such as This breakpoint set
represents the pressure input
.
First point in evenly spaced breakpoint
data. This parameter is available when
Specification is set to
Even spacing
.
Spacing between points in evenly spaced
breakpoint data. This parameter is available when
Specification is set to
Even spacing
.
Name of the Simulink.Breakpoint
object that stores the
information for this breakpoint set.
This column appears only if you set
Specification to
Reference
.
Name of the Simulink.Breakpoint
object that stores the
information for the first point. This parameter is available
when Specification is set to
Even spacing
.
Name of the Simulink.Breakpoint
object that stores
the information for the spacing. This parameter is
available when Specification
is set to Even
spacing
.
Storage class of the structure variable (if you set 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 Code Generation 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).
Alternative name for the structure variable (if you set
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 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, not exceeding 128. For more information about using data alignment for code replacement, see Data Alignment for Code Replacement (Embedded Coder).
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 Specification to
Explicit values
or
Even spacing
.
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
is
the name of the model.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
.
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
is
the name that you specify by using the property Struct Type
definition: Name.StructName
This property appears only if you set Specification to
Explicit values
or
Even spacing
.
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 Specification
to Explicit values
or Even
spacing
.
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:
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.
BP
N — 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.
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:
Select table elements
Use standard keyboard shortcuts such as:
Copy — Ctrl+C
Paste — Ctrl+V
Undo — Ctrl+Z
Delete
Redo — Shift+Ctrl+Z
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Create a Simulink.LookupTable
object
named LUTObj
.
LUTObj = Simulink.LookupTable;
Specify the table data.
LUTObj.Table.Value = [1.1 2.2 3.3 4.4 5.5];
Specify the breakpoint set data.
LUTObj.Breakpoints(1).Value = [-2 -1 0 1 2];
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 View Simulink.LookupTable Object Data Using the Property Dialog Box Tabular Interface.
Create a Simulink.LookupTable
object
named LUTObj
.
LUTObj = Simulink.LookupTable;
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];
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.
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 View Simulink.LookupTable Object Data Using the Property Dialog Box Tabular Interface.
To evenly space every second value starting from 1, use the Breakpoint object.
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]
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]
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: ''
To set the first point property, use the
Breakpoint object FirstPoint
property.
LUTObj.Breakpoints(1).FirstPoint=1
To set the spacing property, use the Breakpoint object.
LUTObj.Breakpoints(1).Spacing=2
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: ''
Create a Simulink.LookupTable
object named LUTObj
.
LUTObj = Simulink.LookupTable;
Specify the table data.
LUTObj.Table.Value = [1.00 2.25 3.50 4.75 6.00; ...
7.25 8.50 9.75 11.00 12.25];
Specify the breakpoint set data. In the Breakpoints
property, use the array index 2
to create an additional Simulink.lookuptable.BreakpointInfo
object, which represents the second breakpoint set.
LUTObj.Breakpoints(1).Value = [-1 1]; LUTObj.Breakpoints(2).Value = [-2 -1 0 1 2];
Specify data types for the lookup table and each breakpoint set.
LUTObj.Table.DataType = 'fixdt(1,16,2)'; LUTObj.Breakpoints(1).DataType = 'int16'; LUTObj.Breakpoints(2).DataType = 'int16';
Specify unique names for the structure fields that store the table data and breakpoint sets in the generated code.
LUTObj.Table.FieldName = 'myTable'; LUTObj.Breakpoints(1).FieldName = 'myBPSet1'; LUTObj.Breakpoints(2).FieldName = 'myBPSet2';
Export the structure variable definition from the generated code by using the storage class ExportedGlobal
.
LUTObj.CoderInfo.StorageClass = 'ExportedGlobal';
Name the structure type in the generated code LUTStructType
. Export the structure type definition to a generated header file named myLUTHdr.h
.
LUTObj.StructTypeInfo.Name = 'LUTStructType'; LUTObj.StructTypeInfo.DataScope = 'Exported'; LUTObj.StructTypeInfo.HeaderFileName = 'myLUTHdr.h';
In an n-D Lookup Table block in a model, set Data specification to Lookup table object
and Name to LUTObj
.
load_system('myModel_LUTObj') set_param('myModel_LUTObj/Lookup Table','DataSpecification','Lookup table object',... 'LookupTableObject','LUTObj')
Generate code from the model.
rtwbuild('myModel_LUTObj')
### Starting build procedure for: myModel_LUTObj ### Generated code for 'myModel_LUTObj' is up to date because no structural, parameter or code replacement library changes were found. ### Successful completion of code generation for: myModel_LUTObj
The generated code defines the structure type LUTStructType
in the generated header file myLUTHdr.h
.
file = fullfile('myModel_LUTObj_ert_rtw','myLUTHdr.h'); rtwdemodbtype(file,'typedef struct {','} LUTStructType;',1,1)
typedef struct { int16_T myBPSet1[2]; int16_T myBPSet2[5]; int16_T myTable[10]; } LUTStructType;
The code uses the global structure variable LUTObj
to store the table and breakpoint set data. The table data is scaled based on the specified fixed-point data type.
file = fullfile('myModel_LUTObj_ert_rtw','myModel_LUTObj.c'); rtwdemodbtype(file,'LUTStructType LUTObj = {','/* Variable: LUTObj',1,1)
LUTStructType LUTObj = { { -1, 1 }, { -2, -1, 0, 1, 2 }, { 4, 29, 9, 34, 14, 39, 19, 44, 24, 49 } } ; /* Variable: LUTObj
Suppose your handwritten code conditionally allocates memory and initializes a lookup table based on dimension lengths that you specify as #define
macros. This example shows how to generate code that uses your external table and breakpoint data.
Symbolic dimensions require that you use an ERT-based system target file, which requires Embedded Coder®.
Explore External Code
In your current folder, copy these macro definitions into a header file named ex_myHdr_LUT.h
.
#include "rtwtypes.h" #ifndef _HEADER_MYHDR_H_ #define _HEADER_MYHDR_H_ #define bp1Len 2 #define bp2Len 2 typedef struct { real_T BP1[bp1Len]; real_T BP2[bp2Len]; real_T Table[bp1Len * bp2Len]; } LUTObj_Type; extern LUTObj_Type LUTObj; #endif
Copy this static initialization code into a source file named ex_mySrc_LUT.c
.
#include "ex_myHdr_LUT.h" #if bp1Len == 2 && bp1Len == 2 LUTObj_Type LUTObj = { { 1.0, 2.0 }, { 3.0, 4.0 }, { 3.0, 2.0, 4.0, 1.0 } } ; #endif #if bp1Len == 3 && bp1Len == 3 LUTObj_Type LUTObj = { { 1.0, 2.0, 3.0 }, { 4.0, 5.0, 6.0 }, { 1.0, 6.0, 2.0, 3.0, 8.0, 9.0, 5.0, 4.0, 7.0 } } ; #endif
To generate code that imports this data, create bp1Len
and bp2Len
as Simulink.Parameter
objects in MATLAB. Create LUTObj
as a Simulink.LookupTable
object. Use the parameter objects to specify the dimension lengths for the table and breakpoint set data in the Simulink.LookupTable
object.
Create Example Model
Create the example model ex_LUTObj
by using an n-D Lookup Table block. In the Lookup Table block dialog box, on the Table and Breakpoints tab, set Number of table dimensions to 2
.
open_system('ex_LUTObj')
Create Simulink.LookupTable
Object
In the Model Explorer Model Hierarchy pane, select Base Workspace.
On the toolbar, click the Add Simulink LookupTable button. A Simulink.LookupTable
object named Object
appears in the base workspace.
In the Contents pane (the middle pane), rename the object as LUTObj
.
Alternatively, create the object at the command prompt:
LUTObj = Simulink.LookupTable;
Configure Simulink.LookupTable
Object
In the Contents pane, select the new object LUTObj
. The property dialog box appears in the Dialog pane (the right pane).
Set Number of table dimensions to 2
.
Under Table, set Value to [3 4; 2 1]
.
In the first row under Breakpoints, set Value to [1 2]
.
In the second row under Breakpoints, set Value to [3 4]
. Click Apply.
Under Struct Type definition, set Data scope to Imported
. Set Header file to ex_myHdr_LUT.h
. Set Name to LUTObj_Type
.
In the Lookup Table block dialog box, set Data specification to Lookup table object
. Set Name to LUTObj
. Click Apply.
Alternatively, to configure the object and the blocks, use these commands:
LUTObj.Breakpoints(1).Value = [1 2]; LUTObj.Breakpoints(2).Value = [3 4]; LUTObj.Table.Value = [3 4; 2 1]; LUTObj.StructTypeInfo.DataScope = 'Imported'; LUTObj.StructTypeInfo.HeaderFileName = 'ex_myHdr_LUT.h'; LUTObj.StructTypeInfo.Name = 'LUTObj_Type'; set_param('ex_LUTObj/Lookup Table','LookupTableObject','LUTObj') set_param('ex_LUTObj/Lookup Table',... 'DataSpecification','Lookup table object')
Enable the code generator to use Simulink.Parameter
objects as macros that specify dimension lengths. Select the configuration parameter Allow symbolic dimension specification.
set_param('ex_LUTObj','AllowSymbolicDim','on')
Create the Simulink.Parameter
objects that represent the macros bp1Len
and bp2Len
. To generate code that imports the macros from your header file ex_myHdr_LUT.h
, apply the storage class ImportedDefine
.
bp1Len = Simulink.Parameter(2); bp1Len.Min = 2; bp1Len.Max = 3; bp1Len.DataType = 'int32'; bp1Len.CoderInfo.StorageClass = 'Custom'; bp1Len.CoderInfo.CustomStorageClass = 'ImportedDefine'; bp1Len.CoderInfo.CustomAttributes.HeaderFile = 'ex_myHdr_LUT.h'; bp2Len = Simulink.Parameter(2); bp2Len.Min = 2; bp2Len.Max = 3; bp2Len.DataType = 'int32'; bp2Len.CoderInfo.StorageClass = 'Custom'; bp2Len.CoderInfo.CustomStorageClass = 'ImportedDefine'; bp2Len.CoderInfo.CustomAttributes.HeaderFile = 'ex_myHdr_LUT.h';
Configure the existing Simulink.LookupTable
object LUTObj
to use the Simulink.Parameter
objects. Set the dimension lengths of the breakpoint set data and the table data by using the names of the parameter objects.
LUTObj.Breakpoints(1).Dimensions = '[1 bp1Len]'; LUTObj.Breakpoints(2).Dimensions = '[1 bp2Len]'; LUTObj.Table.Dimensions = '[bp1Len bp2Len]';
Configure LUTObj
as imported data by applying the storage class ImportFromFile
. To import your definition of LUTObj
, add the name of the file ex_mySrc_LUT.c
to the model configuration parameter Configuration Parameters > Code Generation > Custom Code > Additional Build Information > Source files.
LUTObj.CoderInfo.StorageClass = 'Custom'; LUTObj.CoderInfo.CustomStorageClass = 'ImportFromFile'; LUTObj.CoderInfo.CustomAttributes.HeaderFile = 'ex_myHdr_LUT.h'; set_param('ex_LUTObj','CustomSource','ex_mySrc_LUT.c')
Generate and Inspect Code
Configure the model to compile an executable from the generated code.
set_param('ex_LUTObj','GenCodeOnly','off')
Generate code from the model.
rtwbuild('ex_LUTObj')
### Starting build procedure for: ex_LUTObj ### Successful completion of build procedure for: ex_LUTObj Build Summary Top model targets built: Model Action Rebuild Reason ========================================================================================== ex_LUTObj Code generated and compiled Code generation information file does not exist. 1 of 1 models built (0 models already up to date) Build duration: 0h 0m 17.955s
In the code generation report, view the generated file ex_LUTObj.h
. The file imports the macro definitions and the structure type definition by including your header file ex_myHdr_LUT.h
.
file = fullfile('ex_LUTObj_ert_rtw','ex_LUTObj.h'); rtwdemodbtype(file,'#include "ex_myHdr_LUT.h"','#include "ex_myHdr_LUT.h"',1,1)
#include "ex_myHdr_LUT.h"
In the source file ex_LUTObj.c
, the code algorithm in the model step
function passes the breakpoint and table data to the function that performs the table lookup. The algorithm also passes bp1Len
so the lookup function can traverse the rows and columns of the table data, which appear in the generated code as a serialized 1-D array.
file = fullfile('ex_LUTObj_ert_rtw','ex_LUTObj.c'); rtwdemodbtype(file,'/* Model step function */','/* Model initialize function */',1,0)
/* Model step function */ void ex_LUTObj_step(void) { /* Outport: '<Root>/Out1' incorporates: * Inport: '<Root>/In1' * Inport: '<Root>/In2' * Lookup_n-D: '<Root>/Lookup Table' */ ex_LUTObj_Y.Out1 = look2_binlcapw(ex_LUTObj_U.In1, ex_LUTObj_U.In2, (&(LUTObj.BP1[0])), (&(LUTObj.BP2[0])), (&(LUTObj.Table[0])), ex_LUTObj_ConstP.LookupTable_maxIndex, (uint32_T)bp1Len); }
You cannot subclass Simulink.Breakpoint
or Simulink.LookupTable
.
For this reason, you cannot apply custom storage classes other than
those in the built-in Simulink
package.
You cannot use Simulink.Breakpoint
objects
or Simulink.LookupTable
objects that refer to Simulink.Breakpoint
objects
as instance-specific parameter data for reusable components. For example,
you cannot use one of these objects as:
A model argument in a model workspace or a model argument value in a Model block.
The value of a mask parameter on a CodeReuse Subsystem block.
The value of a mask parameter on a subsystem that you reuse by creating a custom library.
However, you can use standalone Simulink.LookupTable
objects,
which do not refer to Simulink.Breakpoint
objects,
in these ways.
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.
Simulink.Breakpoint
| Simulink.lookuptable.Breakpoint
| Simulink.lookuptable.Evenspacing
| Simulink.lookuptable.StructTypeInfo
| Simulink.lookuptable.Table
| Simulink.Parameter