Main Content

Unbounded Variable-Size Signal Basic Operations

This example shows how to use unbounded variable-size signals in Simulink® modeling. For more information about the general concept of unbounded variable-size signals, see Unbounded Variable-Size Signals.

This model describes how to configure blocks to use unbounded variable-size signals.

open_system('ex_boundedsignals')

To display the signal dimensions, in the Simulink Editor, on the Debug tab, select Information Overlays and click Signal Dimensions.

Model with blocks that use signals with finite size

The following sections describe how to configure the Inport block, MATLAB Function block, Simulink Signal object and Simulink Bus object to use unbounded variable-size signals.

Configure Inport Block to Generate Unbounded Variable-Size Signals

In the block dialog box:

  • On the Signal Attributes tab, set the appropriate values of Port dimensions as Inf. For Variable-size signal, select Yes to allow variable-size signals.

  • On the Execution tab, specify Sample time explicitly and clear Interpolate data.

For example, the Inport1 block connected to the input port of the Selector block is configured to generate an unbounded variable-size signal with dimension [Inf 6], data type uint16, and sample time 1. You can configure all the other Inport blocks similarly to generate unbounded variable-size signals. In this example, configure the Inport2 block and Inport3 block to generate unbounded variable-size signals with sample time 1 and dimensions [Inf Inf] and [Inf Inf Inf] respectively.

To use an unbounded variable-size signal as index signal to the Selector block, replace the Constant block with an Inport block. Configure the Inport block to generate the index signal with dimension Inf, data type uint16 and sample time 1. Also, for the Selector block, in the Block Parameters dialog box, select Number of input dimensions as 2, Index Option as Index vector (dialog) as [3 4 5].

The block parameters dialog box shows signal attributes for the unbounded variable-size signals

The block parameters dialog box shows execution settings for the unbounded variable-size signals

Configure MATLAB Function Block to Support Unbounded Variable-Size Signals

Specify the size of a variable-size input/output signal associated with the MATLAB Function block. To interactively configure the MATLAB Function block, in the Simulink Editor, on the Modeling tab, from the Design gallery, select Model Explorer. From the Model Explorer window, select the MATLAB Function. Set the dimension in Size to [Inf 6] and select Variable size.

The Model Explorer shows settings for the MATLAB Function block that is configured to support unbounded variable-size signals

Configure Simulink Signal Object to Support Unbounded Variable-Size Signals

Specify the size of a variable-size Simulink.Signal object as unbounded. To programmatically configure the signals, in the Simulink Editor, on the Modeling tab, select Model Settings > Model Properties. In the Model Properties dialog box, on the Callbacks tab, select PreLoadFcn to edit the Simulink.Signal object properties.

For the signal object:

  • Set Dimensions value to Inf.

  • Set DimensionsMode to Variable.

Simulink signal object configured to support unbounded variable-size signals

Configure Simulink Bus Object to Support Unbounded Variable-Size Signals

Specify the size of a variable-size Simulink.Bus object as unbounded. To programmatically configure the bus elements, in the Simulink Editor, on the Modeling tab, select Model Settings > Model Properties. In the Model Properties dialog, on the Callbacks tab, select PreLoadFcn to edit the Simulink.BusElement object properties.

For each bus element:

  • Set appropriate dimensions to infinity by setting Dimensions value to Inf.

  • Set DimensionsMode to Variable.

Simulink Bus Elements configured to support unbounded variable-size signals

Configure Data Store for Unbounded Variable-Size Signals

To Configure the Data Store Memory block to store bus object A, in the Data Store Memory dialog box, on the Signal Attributes tab, set Data type to Bus:A.

Compile the Model and Verify Signal Dimensions

Once you configure the blocks and Simulink objects, update (Ctrl+D) the model. Save (Ctrl+S) the model in the working folder and close it. Re-open the model for the updated properties of Simulink.BusElement and Simulink.Signal objects to be effective.

To verify if the model components are properly configured to support unbounded variable-size signals, check the signal dimensions. To display the signal dimensions, in the Simulink Editor, on the Debug tab, click Information Overlays and select Signal Dimensions.

Model with blocks that use unbounded variable-size signals

Set Model Configuration Parameters for Simulation

In the Simulink Editor, on the Modeling tab, select Model Settings. In the Configuration Parameters dialog box:

  • On the Solver tab, check that the solver is set to auto (default). Otherwise, select auto / discrete.

  • On the Data Import/Export tab, check that the Format is set to Dataset (default).

  • On the Simulation Target tab, set Language as C++. In Advanced parameters section, check that Dynamic memory allocation in MATLAB functions is selected.

Set Up Data Logging

To log the output signals from the Data Store Read block, use the Outport block. In this case, the output signals sig1 and sig3 are Simulink bus elements.

See Also

| | | |

Related Topics