Documentation Center

  • Trial Software
  • Product Updates

Contents

Convert Models to Use Arrays of Buses

There are several reasons to convert a model to use an array of buses (see Benefits of 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 that has grown in complexity.

General Conversion Approach

This section presents 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 details about these techniques, see Combine Buses into an Array of Buses and Arrays of Buses in Models.

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 signal 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 new 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 signal is a bus of buses, where each element bus signal is of the same type.

    • The bus that you convert must be a nonvirtual bus. You can convert a virtual bus to a nonvirtual bus if all elements of the target bus have the same sample time (or if the sample time is inherited).

    • The target bus cannot have variable-dimensioned and frame-based elements.

  2. Use a Concatenate block to convert the original bus of buses signal 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 signal is BusObject. The new model eliminates the wrapper bus signal (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 signal 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 signal and concatenate the output bus signal.

    The scalar algorithm within the For-Each subsystem cannot have continuous states. For additional limitations, see the For Each Subsystem block documentation.

Was this topic helpful?