Use Symbolic Expressions to Design Simulink Model
Symbolic dimensions allow you to use symbols that represent values you can change instead of fixed numerical values for signal dimensions during model development. For more information, see Create a Model with Symbolic Dimensions.
You can apply MATLAB® expressions while using symbolic dimensions to establish relationships or dependencies between signals. This is useful for modeling systems where signals are interdependent. For more information on setting variables and parameters using MATLAB expressions, see Set Variable Value by Using a Mathematical Expression.
Simulink® evaluates MATLAB expressions used to define signal dimensions during simulation to verify consistency between the signals based on the numerical values assigned to the symbols. You can visualize the propagation of symbolic dimensions during simulation and verify that they agree with the evaluated values of the expressions that you use to define them. Simulink reports an error if it encounters any discrepancies with the numerical values assigned to symbolic dimensions when evaluating them. When the code is generated using symbolic expressions, they are encapsulated in preprocessor conditionals.
Propagation of Symbolic Dimensions in Simulink Blocks
When a Simulink block supports symbolic dimension propagation, it preserves the symbolic
dimensions during model simulation and code generation. For example, when signals with
symbolic dimensions A
and B
pass through a Vector
Concatenate block, the inputs are concatenated to produce a signal with dimension
A + B
as output.
In this case, the value of A + B
must equal to C
in
order for the symbolic dimensions to propagate through the Add
block.
You can also establish modeling constraints by defining minimum and maximum values for a signal dimension to prevent using values outside a specified range. If you provide a signal dimension which is outside the specified range, Simulink reports an error during simulation. For more information on minimum and maximum values for a parameter, see Specify Parameter Value Ranges.
Supported Operators for Symbolic Expressions
This table lists the MATLAB operators you can use to define symbolic expressions and their corresponding
representation in the generated code. In these examples, A
and
B
are expressions that evaluate to an integer, and x
is a constant integer literal.
MATLAB Expressions | Equivalent Expression in C Preprocessor Conditional of Generated Code |
---|---|
Arithmetic | |
|
|
|
|
|
|
|
|
A * B | A * B |
idivide(A,B) |
|
rem(A,B) |
|
Relational | |
| A == B |
| A != B |
| A < B |
| A > B |
| A <= B |
| A >= B |
Logical | |
~A | !A , where A is not an integer |
A && B | A && B |
A || B | A || B |
Bitwise
(A and B cannot both be constant integer
literals) | |
| A & B |
| A | B |
| A ^ B |
| ~A |
| A << x |
| A >> x |