Work with Arrays of Buses - MATLAB & Simulink (original) (raw)

Setting up a model to use an array of buses usually involves these tasks:

  1. Define the array of buses. See Create Array of Buses from Nonvirtual Buses.
  2. Add a subsystem for performing iterative processing on each element of the array of buses. See Perform Iterative Processing.
  3. Model your scalar algorithm within the iterative processing subsystem.
    1. Operate on the array of buses (using Selector andAssignment blocks).
    2. Use the Bus Selector and Bus Assignment blocks to select elements from, or assign elements to, a nonvirtual bus within the subsystem.
      See Assign Values into Arrays of Buses and Select Bus Elements from Array of Buses.
  4. Optionally, import or log array of buses data. See Load Data for Arrays of Buses and Log Arrays of Buses.

The resulting model creates the array of buses and uses a subsystem to iteratively process the elements of the array.

Nonvirtual buses are grouped in an array of buses that is input to a subsystem that provides iterative processing.

Perform Iterative Processing

You can perform iterative processing on the bus data of an array of buses using blocks such as the For Each Subsystem, While Iterator Subsystem, and For Iterator Subsystem blocks. You can use one of these blocks to perform the same kind of processing on:

Assign Values into Arrays of Buses

How you assign values to one or more elements in an array of buses depends on your modeling requirement.

Select Bus Elements from Array of Buses

To select a bus element from an array of buses:

  1. Use a Selector block to select a bus from the array of buses. The input array of buses can have any dimension. The output bus of theSelector block is a selected or reordered set of elements from the input array of buses.
  2. Use a Bus Selector block to select a bus element from the bus. The input for the Bus Selector block must be a bus.

For an example, see Model Arrays of Buses.

Load Data for Arrays of Buses

Several blocks support loading external input data for an array of buses into your model for simulation. The table summarizes array of buses support for loading blocks.

Block Array of Buses Support
Inport Supported.For more information, see Load Bus Data to Root-Level Input Ports.
In Bus Element Supported.You cannot select elements of the array of buses. You must load the entire array of buses. For more information, see In Bus Element.
Signal Editor Supported.
From Workspace Supported.For more information, see Load Data Using the From Workspace Block.
Playback Supported.When you load bus data, the Playback block assigns a port to each element of the bus.
From File Not supported.
From Spreadsheet Not supported.

Log Arrays of Buses

To export an array of buses, mark the signal for signal logging. For more information, see Save Run-Time Data from Simulation.

Note

Simulink® does not log signals inside referenced models in rapid accelerator mode.

To access the signal logging data for a specific signal in an array of buses, navigate through the structure hierarchy and specify the index to the specific signal. For details, see Access Bus Data Logged Using Dataset Format.

Root level bus outputs are not logged when you select the Output configuration parameter. Use standard signal logging instead, as described in Save Signal Data Using Signal Logging.

Do not use signal logging for buses or arrays of buses directly from within a for-each subsystem. Either use a Bus Selector block to select the bus element signals to log or add an Outport block outside of the subsystem and then log that signal. For details, see Log Signals in For-Each Subsystems.

Note

Signal logging is supported for arrays of buses with variable-size signals only when running a simulation in normal mode. (since R2023a)

Initialize Arrays of Buses

To specify a unique initial value for each of the individual signals in an array of buses, you can use an array of initial condition structures. Each structure in the array initializes one of the buses.

To initialize an array of buses with structure parameters, you can use:

You cannot use partial structures.

For examples, see Initialize Buses and Arrays of Buses Using MATLAB Structure from Type Editor and Programmatically Initialize Arrays of Buses.

Code Generation

Code generation for arrays of buses produces structures with a specific format. SeeCode Generation for Arrays of Buses.

Note

Code generation is not supported for arrays of buses with variable-size signals.

See Also

Topics