Unbounded Variable-Size Signals
In Simulink®, variable-size signals are signals whose size (the number of elements in a
dimension), in addition to its values can change during model simulation. For example, a
variable-size signal with dimensions
[2 5] allows the first dimension to
vary in the range of
[0 2] and the second dimension to vary in the range of
Unbounded variable-size signals extend the functionality of variable-size signals by
modeling data whose sizes are unknown during model compilation. You can configure an unbounded
variable-size signal by specifying the size of a variable-size signal as
Inf. For example, an unbounded variable-size signal with dimension
[2 Inf] allows the first dimension to vary in the range of
2] and the second dimension in the range of
intmax("int32") indicates the maximum allowable
size limit. For more information, see Maximum Size Limits of Simulink Models.
Unbounded variable-size signals use dynamic memory allocation and deallocation to react to varying signal sizes during model simulation. This functionality allows efficient storage and management of signal data.
Unbounded variable-size signals can be beneficial in these scenarios:
Data storage — Unbounded variable-size signals gives you the flexibility to model signals without specifying a potentially conservative finite signal size (upper bound), resulting in more efficient use of available memory.
Code generation — When you interface code generated from Simulink models with external libraries or APIs that operate on dynamic arrays, using unbounded variable-size signals allow Simulink code components to easily exchange data with other external software components. For more information, Variable-Size Signals in Generated Code (Simulink Coder).
This table describes the differences between bounded and unbounded variable-size signals.
|Attribute||Bounded Variable-Size Signals||Unbounded Variable-Size Signals|
|Signal size||Specify a finite signal size for model compilation.||Specify signal size as |
|Memory allocation||Memory is allocated statically at run time based on the signal size specified for model compilation.||Memory is allocated dynamically based on the signal size during model simulation.|
|Code generation||Suitable for deployment to memory constrained embedded targets.||Suitable for deployment to desktop quality targets.|
A subset of Simulink blocks and Simulink features support unbounded variable-size signals. For more information, see Supported Blocks and Features for Simulation.
To ensure optimal model configuration and avoid workflow errors, it is recommended to avoid using both unbounded and bounded variable-size signals in the same model.
Using Unbounded Variable-Size Signals
Follow these steps to use unbounded variable-size signals in a model.
Determine Whether Model Meets Requirements
Determine whether your model meets the requirements to use unbounded variable-size signals.
For each model component and for component interfaces, identify the signals whose sizes are unknown at model compilation.
Check if the source and sink blocks for the signals support unbounded variable-size signals:
If the blocks are not supported, you must define finite values for all the dimensions of such signals. In this case, the next steps and sections do not apply to your model.
If the blocks are supported, proceed to the next step. For more information about the blocks supported, see Supported Blocks.
If the blocks are supported but the model features are not supported, you must change to supported model features. For more information, see Supported Features.
Configure Model Components
Configure the model based on whether signals are associated with blocks or contained in signal or bus objects.
These are four typical configuration scenarios:
For more information, see Unbounded Variable-Size Signal Basic Operations.
Compile Model and Verify Signal Dimensions
Verify if the model is configured to handle unbounded variable-size signals.
Update the block diagram (Ctrl+D).
In the Simulink Editor, on the Debug tab, select Information Overlays and click Signal Dimensions.
Each signal is labelled with its dimensions, so you can check that the signals are properly configured to carry unbounded size data.
Prepare Model for Simulation
To prepare the model for simulation, in the Configuration Parameters dialog box:
In the Solver pane, in the Solver Selection section, check that Solver is set to the default
autooption. Otherwise, select
auto(Automatic Solver Selection)or
discrete(no continuous states). Unbounded variable-size signals only support discrete solvers.
In the Data Import/Export pane, check that the data logging Format is set to
You will need additional configuration settings when you use MATLAB Function block or plan to generate C++ code from the model. For the MATLAB Function block, see Unbounded Variable-Size Arrays in MATLAB Function Block. For code generation, see Unbounded Variable-Size Signals in C++ Code Generation.
Set Up Data Logging
You can log unbounded variable-size signals using any of the mechanism described in View the Signal Logging Configuration. Logging non-virtual buses that contain unbounded variable-size signals is not supported.
Unbounded Variable-Size Signals in C++ Code Generation
Configure the model for code generation. In the Code Generation pane:
Set the target language to
In the Interface section, set Array Layout to
For more information about code generation, see Variable-Size Signals in Generated Code (Simulink Coder).
Unbounded Variable-Size Arrays in MATLAB Function Block
You must use MATLAB Function blocks to implement math operations for unbounded variable-size signals, because nonvirtual mathematical operation blocks are not supported. For more information, see Limitations.
When using a MATLAB Function block, in the Simulation Target pane:
In Advanced parameters section, check that Dynamic memory allocation in MATLAB functions is selected. This option is selected by default. For more information, see Declare Variable-Size MATLAB Function Block Variables.
Set Language as
When using unbounded variable-size signals, MATLAB Function blocks use dynamic memory allocation. For more information, see Control Memory Allocation for Variable-Size Arrays in a MATLAB Function Block.
For an example that has a MATLAB Function block which uses unbounded variable-size arrays, see Unbounded Variable-Size Signal Basic Operations.
Supported Blocks and Features for Simulation
These Simulink blocks support unbounded variable-size signals. The list below shows the blocks based on the Simulink Library they belong to. To access Simulink Library, in the Simulink Toolstrip, on the Simulation tab, click Library Browser.
Simulink / Port & Subsystems
Simulink / Signal Attributes
Simulink / User-Defined Functions
Simulink / Sources
Simulink / Sinks
Simulink / Math Operations
Normal simulation mode for top-level model in a model hierarchy
Both Normal and Accelerator simulation modes for referenced models
All data types except string
Unbounded variable-size signals are not supported for these blocks.
For Each Subsystem block.
Nonvirtual mathematical operation blocks, including but not limited to the Gain block, Add block, Product, Matrix Multiply block, Math Function block, and Trigonometric Function block. To implement these math operations for unbounded variable-size signals, use the MATLAB Function block or the S-Function block.