Main Content

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.

The original modeling pattern uses three subsystems. The new modeling pattern uses one for-each subsystem.

In the original modeling pattern:

  • The target bus to be converted is named MainBus, and it has three elements, each of type BusObject.

  • The ScalarAlgorithm1, ScalarAlgorithm2, and ScalarAlgorithm3 subsystems 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 MainBus to 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 MainBus involves changing the Bus object 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:

  1. 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.

  2. 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 MainBus signal. 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 (MainBus).

  3. 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 MainBus signal in the original model.

  4. 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.

Related Topics