Symbolic Dimensions Limitations for Code Generation - MATLAB & Simulink (original) (raw)
Main Content
The Simulink Block Data Type Support table includes a column identifying the blocks that supports symbolic dimension propagation. To find out which blocks support symbolic dimension specification, enter showblockdatatypetable
at the MATLAB command prompt and see symbolic dimension support column.
Code Generation Optimization Considerations
When you create a model with symbolic dimensions, consider the following optimization aspects:
- The code generator reuses buffers only if dimension propagation establishes equivalence among buffers.
- Two loops with symbolic loop bound calculations are fused together only if they share equivalent symbolic expression.
- Optimizations do not eliminate a symbolic expression or condition check based on the current value of a symbolic dimension.
Symbolic Dimensions Limitations
The following products and software capabilities support symbolic dimensions by acting on their numeric values. However, they do not support the propagation of symbolic dimensions during model simulation and the preservation of symbolic dimensions in the generated code.
- Code Replacement for Lookup Tables
- Software-in-the-Loop (SIL) and Processor-in-the-Loop (PIL) simulations
- Accelerator and rapid accelerator simulation modes
- Scope and simulation observation (for example, logging, SDI, and so on)
- Model coverage
- Simulink Design Verifier
- Fixed-Point Designer
- Data Dictionary
- Simulink PLC Coder
- HDL Coder
The following do not support symbolic dimensions:
- System Object
- Stateflow charts that use MATLAB as the action language
- Physical modeling
- Discrete-event simulation
- Frame data
- MATLAB functions
Additional Limitations for Models Using Symbolic Dimensions
The following limitations also apply to models that utilize symbolic dimensions.
- For simulation, the size of a symbolic dimension can be 1. For code generation, the size of a symbolic dimension must be greater than
1
. - The symbolic dimension is expressed in the code as a macro (
#define
) corresponding to a literal number. The compiler interprets this number as integer data type, and because of this, the data type for the symbolic dimension should match the target integer type to ensure compatibility. - Code generation is not supported if Variable-size signals configuration parameter is enabled for models with symbolic dimensions.
- If a symbolic dimension is a MATLAB expression that includes an arithmetic expression combined with a relational or logical expressions, add
+0
after the relational or logical part of the MATLAB expression to avoid simulation errors. Adding+0
converts the data type of the relational or logical part of the expression from aboolean
to adouble
.
For example, if you have an expression[(C==8)*D+E,3]
with theData type parameter set todouble
. SinceC==8
is a relational expression, you must modify the expression to[((C==8)+0)*D+E,3]
to avoid simulation errors. - Simulink propagates symbolic dimensions for an entire structure or matrix but not for a part of a structure or matrix. For example, consider the
Simulink.Parameter
P
is a2x3
matrix with symbolic dimensions[Dim,Dim1]
.
p=Simulink.Parameter(struct('A',[1 2 3;4 5 6]))
p.DataType='Bus:bo'
bo=Simulink.Bus
bo.Elements(1).Name='A'
bo.Elements(1).Dimensions='[Dim,Dim1]'
Dim=Simulink.Parameter(2)
Dim1=Simulink.Parameter(3)
p.CoderInfo.StorageClass='Custom'
p.CoderInfo.CustomStorageClass='Define'
Dim.CoderInfo.StorageClass='Custom'
Dim.CoderInfo.CustomStorageClass='Define'
Dim1.CoderInfo.StorageClass='Custom'
Dim1.CoderInfo.CustomStorageClass='Define'
If you specifyp.A
for a dimensions parameter, Simulink propagates the symbolic dimensions[Dim,Dim1]
. If you specifyp.A(1,:)
, Simulink propagates the numeric dimension3
but not the symbolic dimension,Dim1
. - MATLAB expressions that do not maintain symbolic dimension information:
A(:)
. UseA
instead.P(2:A)
. Use the Selector block instead.P(2,:)
, not a tunable expression.
- Suppose that you set the value of a mask parameter,
myMaskParam
, by using a field of a structure or by using a subset of the structures in an array of structures. You store the structure or array of structures in aSimulink.Parameter
object so that you can use aSimulink.Bus
object to apply symbolic dimensions to the structure fields. Under the mask, you configure a block parameter to use one of the fields that have symbolic dimensions. The table shows some example cases.Description Value of mask parameter (myMaskParam) Value of block parameter myStruct is a structure with fieldgains, which uses symbolic dimensions. myStruct.gains myMaskParam myStruct is a structure with field hierarchymyStruct.subStruct.gains. The fieldgains uses symbolic dimensions. myStruct.subStruct myMaskParam.gains myStructs is an array of structures. Each structure has a field gains, which uses symbolic dimensions. myStructs(2) myMaskParam.gains In these cases, you cannot generate code from the model. As a workaround, choose one of these techniques: - Use the entire structure (
myStruct
) or array of structures (myStructs
) as the value of the mask parameter. Under the mask, configure the block parameter to dereference the target field from the mask parameter by using an expression such asmyMaskParam.subStruct.gains
. - Use literal dimensions instead of symbolic dimensions for the target field (
gains
).
This limitation also applies when you use a field of a structure or a subset of the structures in an array of structures as the value of a model argument in aModel block.
- Use the entire structure (