Work with Arrays of Buses
Setting up a model to use an array of buses usually involves these tasks:
Define the array of buses. See Create Array of Buses from Nonvirtual Buses.
Add a subsystem for performing iterative processing on each element of the array of buses. See Perform Iterative Processing.
Model your scalar algorithm within the iterative processing subsystem.
Operate on the array of buses (using Selector and Assignment blocks).
Use the Bus Selector and Bus Assignment blocks to select elements from, or assign elements to, a nonvirtual bus within the subsystem.
The resulting model creates the array of buses and uses a subsystem to iteratively process the elements of the array.
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.
To assign values to specified elements in a bus, use a Bus Assignment block. Access the bus in a subsystem such as a for-each subsystem or by selecting a bus from the array of buses with a Selector block. For an example, see Assign Signal Values to Bus Elements.
A Bus Assignment block can also assign or fully replace an array of buses that is an element of a bus.
Select Bus Elements from Array of Buses
To select a bus element from an array of buses:
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.
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
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.
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.
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:
0. In this case, all the individual signals in the array of buses use the initial value
structthat 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:
Numeric data type, such as
You cannot use partial structures.
Code generation for arrays of buses produces structures with a specific format. See Code Generation for Arrays of Buses.
Code generation is not supported for arrays of buses with variable-size signals.