Main Content

Work with Arrays of Buses

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 and Assignment 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 Import Array of Buses Data 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:

  • Each bus in the array of buses

  • A selected subset of buses in the array of buses

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 the Selector 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.

Import Array of Buses Data

Use a root Inport block to import (load) an array of structures of MATLAB® timeseries objects for an array of buses. You can import partial data into the array of buses. For more information, see Import Array of Buses Data.

You cannot use a From Workspace or From File block to import data for an array of buses.

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 Array of Buses Signal Logging Data.

Root level bus outputs are not logged when you select the Output configuration parameter. Use standard signal logging instead, as described in Export 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 not supported for arrays of buses with variable-size signals.

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:

  • The number 0. In this case, all the individual signals in the array of buses use the initial value 0.

  • A scalar struct that represents the same hierarchy of fields and field names as the bus type. In this case, the scalar structure expands to initialize each of the individual signals in the array of buses.

  • An array of structures that specifies an initial value for each of the individual signals in the array of buses.

    If you use an array of structures, all the structures in the array must have the same hierarchy of fields. Each field in the hierarchy must have the same characteristics across the array:

    • Field name

    • Numeric data type, such as single or int32

    • Complexity

    • Dimensions

You cannot use partial structures.

For examples, see Initialize Buses and Arrays of Buses Using Bus Editor and Initialize Arrays of Buses Programmatically.

Code Generation

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

Note

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

Related Topics