Convert Models to Use Arrays of Buses
There are several reasons to convert a model to use an array of buses. For example:
The model was developed before Simulink® supported arrays of buses (introduced in R2010b), and the model contains many subsystems that perform the same kind of processing.
The model has grown in complexity.
General Conversion Approach
Here is a general approach for converting a model that contains buses to a model that uses an array of buses. The method that you use depends on your model. For more information, see Group Nonvirtual Buses in Arrays of Buses.
This workflow refers to a stylized example model. The example shows the original modeling pattern and a new modeling pattern that uses an array of buses.
In the original modeling pattern:
The target bus to be converted is named
MainBus, and it has three elements, each of type
ScalarAlgorithm3subsystems encapsulate the algorithms that operate on each of the bus elements. The subsystems all have the same content.
A Bus Selector block picks out each element of
MainBusto drive the subsystems.
The construction in the original modeling pattern is inefficient for two reasons:
A copy of the subsystem that encapsulates the algorithm is made for each element of the bus that is to be processed.
Adding another element to
MainBusinvolves changing the
Busobject definition and the Bus Selector block, and adding a subsystem. Each of these changes is a potential source of error.
To convert the original modeling pattern to use an array of buses:
Identify the target bus and associated algorithm that you want to convert. Typically, the target bus is a bus of buses, where each element bus is of the same type.
The bus that you convert must be a nonvirtual bus. If all elements of the target bus have the same sample time (or if the sample time is inherited), you can convert a virtual bus to a nonvirtual bus.
The target bus cannot have variable-dimensioned and frame-based elements.
Use a Concatenate block to convert the original bus of buses to an array of buses.
In the example, the new modeling pattern uses a Vector Concatenate block to replace the Bus Creator block that creates the
MainBussignal. The output of the Vector Concatenate block is an array of buses, where the type of the bus is
BusObject. The new model eliminates the wrapper bus (
Replace all identical copies of the algorithm subsystem with a single for-each subsystem that encapsulates the scalar algorithm. Connect the array of buses to the for-each subsystem.
The new model eliminates the Bus Selector blocks that separate out the elements of the
MainBussignal in the original model.
Configure the For Each Subsystem block to iterate over the input array of buses and concatenate the output bus.
The scalar algorithm within the for-each subsystem cannot have continuous states. For additional limitations, see the For Each Subsystem block documentation.