To configure symbolic dimensions for S-function blocks, you can use the following C/C++ functions. You can configure S-functions to support forward propagation, backward propagation, or forward and backward propagation of symbolic dimensions during simulation.
Many of these functions return the variable SymbDimsId
. A
SymbDimsId
is a unique integer value. This value corresponds to each
symbolic dimension specification that you create or is the result of a mathematical operation
that you perform with symbolic dimensions.
C/C++ S-Functions | Purpose |
---|---|
Specify whether or not an S-function supports symbolic dimensions. | |
Specify the symbolic dimensions of an input port and how those dimensions propagate forward. | |
Specify the symbolic dimensions of an output port and how those dimensions propagate backward. | |
Create a | |
Create a | |
Create a | |
Create a | |
Create a | |
Create a | |
Create a | |
Create a | |
Get the number of dimensions for a | |
Get a | |
Set the precompiled | |
Get the compiled | |
Set the compiled | |
Set the precompiled | |
Get the compiled | |
Set the compiled | |
Set the compiled |
This S-function subtracts the symbolic dimension B
from
a symbolic input dimension. It does not support backward propagation
of symbolic dimensions because the compiled symbolic dimensions of
the input port are not set. Symbolic dimensions are
set for the output port, so forward propagation occurs.
static void mdlInitializeSizes(SimStruct *S) { // Enable symbolic dimensions for the s-function. ssSetSymbolicDimsSupport(S, true); } #if defined(MATLAB_MEX_FILE) #define MDL_SET_INPUT_PORT_SYMBOLIC_DIMENSIONS static void mdlSetInputPortSymbolicDimensions(SimStruct* S, int_T portIndex, SymbDimsId symbDimsId) { assert(0 == portIndex); // Set the compiled input symbolic dimension. ssSetCompInputPortSymbolicDimsId(S, portIndex, symbDimsId); // Register "B" and get its symbolic dimensions id. const SymbDimsId symbolIdForB = ssRegisterSymbolicDimsString(S, "B"); // Subtract "B" from the input symbolic dimension. const SymbDimsId outputDimsId = ssRegisterSymbolicDimsMinus(S, symbDimsId, symbolIdForB); //Set the resulting symbolic dimensions id as the output. ssSetCompOutputPortSymbolicDimsId(S, portIndex, outputDimsId); } #endif #if defined(MATLAB_MEX_FILE) #define MDL_SET_OUTPUT_PORT_SYMBOLIC_DIMENSIONS static void mdlSetOutputPortSymbolicDimensions(SimStruct *S, int_T portIndex, SymbDimsId symbDimsId) { assert(0 == portIndex); // The input dimensions are not set, so this S-function only // supports forward propagation. ssSetCompOutputPortSymbolicDimsId(S, portIndex, symbDimsId); } #endif
This S-function transposes two symbolic dimensions. It supports forward and backward propagation of symbolic dimensions because the compiled symbolic dimension of both the input and output ports are set.
static void mdlInitializeSizes(SimStruct *S) { // Enable symbolic dimensions for the s-function. ssSetSymbolicDimsSupport(S, true); } #if defined(MATLAB_MEX_FILE) #define MDL_SET_INPUT_PORT_SYMBOLIC_DIMENSIONS static void mdlSetInputPortSymbolicDimensions(SimStruct* S, int_T portIndex, SymbDimsId symbDimsId) { assert(0 == portIndex); ssSetCompInputPortSymbolicDimsId(S, portIndex, symbDimsId); assert(2U == ssGetNumSymbolicDims(S, symbDimsId)); if (SL_INHERIT == ssGetCompOutputPortSymbolicDimsId(S, portIndex)) { const SymbDimsId idVec[] = { ssGetSymbolicDim(S, symbDimsId, 1), ssGetSymbolicDim(S, symbDimsId, 0)}; // Register the transposed dimensions. // Set the output symbolic dimension to the resulting id. const SymbDimsId outputDimsId = ssRegisterSymbolicDims(S, idVec, 2U); ssSetCompOutputPortSymbolicDimsId(S, portIndex, outputDimsId); } } #endif #if defined(MATLAB_MEX_FILE) #define MDL_SET_OUTPUT_PORT_SYMBOLIC_DIMENSIONS static void mdlSetOutputPortSymbolicDimensions(SimStruct *S, int_T portIndex, SymbDimsId symbDimsId) { assert(0 == portIndex); ssSetCompOutputPortSymbolicDimsId(S, portIndex, symbDimsId); assert(2U == ssGetNumSymbolicDims(S, symbDimsId)); if (SL_INHERIT == ssGetCompInputPortSymbolicDimsId(S, portIndex)) { const SymbDimsId idVec[] = { ssGetSymbolicDim(S, symbDimsId, 1), ssGetSymbolicDim(S, symbDimsId, 0)}; const SymbDimsId inputDimsId = ssRegisterSymbolicDims(S, idVec, 2U); // Register the transposed dimensions. // Set the input symbolic dimension to the resulting id. ssSetCompInputPortSymbolicDimsId(S, portIndex, inputDimsId); } } #endif