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, seeGroup 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 namedMainBus, and it has three elements, each of typeBusObject.

  • TheScalarAlgorithm1,ScalarAlgorithm2, andScalarAlgorithm3subsystems encapsulate the algorithms that operate on each of the bus elements. The subsystems all have the same content.

  • ABus Selectorblock picks out each element ofMainBusto 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 toMainBusinvolves changing theBusobject definition and theBus Selectorblock, 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. 确定目标总线和相关算法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 aConcatenateblock to convert the original bus of buses to an array of buses.

    In the example, the new modeling pattern uses aVector Concatenateblock to replace theBus Creatorblock that creates theMainBussignal. The output of theVector Concatenateblock is an array of buses, where the type of the bus isBusObject. 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 theBus Selectorblocks that separate out the elements of theMainBussignal in the original model.

  4. Configure theFor Each Subsystemblock 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 theFor Each Subsystemblock documentation.

Related Topics