Main Content

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 [0 5].

Unbounded variable-size signals or dynamic arrays 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 [0 2] and the second dimension in the range of [0 intmax("int32")]. 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.

AttributeBounded Variable-Size SignalsUnbounded Variable-Size Signals
Signal sizeSpecify a finite signal size for model compilation.Specify signal size as Inf for model compilation.
Memory allocationMemory 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 generationSuitable for deployment to memory constrained embedded targets.Suitable for deployment to desktop quality targets.

Note

A subset of Simulink blocks and Simulink features support unbounded variable-size signals. For more information, see Supported Blocks and Features for Simulation.

Note

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.

  1. For each model component and for component interfaces, identify the signals whose sizes are unknown at model compilation.

  2. 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.

  3. 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:

  • Unbounded variable-size signals associated with the Inport block

  • Unbounded variable-size signals associated with the input or output port of the MATLAB Function block

    Unbounded variable-size signals connected to Inport and MATLAB Function blocks

  • Unbounded variable-size Simulink.BusElement objects contained in Simulink.Bus object

    Unbounded variable-size signals contained in a Simulink Bus object connected to a Bus Creator block

  • Unbounded variable-size Simulink.Signal object

    Unbounded variable-size signal contained in a Simulink Signal object named indexSig that is connected to a For Iterator Subsystem block

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 labeled with its dimensions, so you can check that the signals are properly configured to carry unbounded size data.

Model with components configured to use unbounded variable-size signals

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 auto option. 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 Dataset (default).

Note

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 C++.

  • In the Interface section, select Support: variable-size signals and set Array Layout to Column-major.

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.

When using a MATLAB Function block, in the Simulation Target pane:

When using unbounded variable-size signals, MATLAB Function blocks use dynamic memory allocation. For more information, see Use Dynamic 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

This section lists blocks and features that you can use with unbounded variable-size signals. Any block or feature not listed in this section is not supported.

Supported Blocks

These Simulink blocks support unbounded variable-size signals. The list below shows the blocks based on the Simulink library they belong to. To access the Simulink Library Browser, in the Simulink Toolstrip, on the Simulation tab, click Library Browser.

Supported Features

  • 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

Related Topics