Skip to Main Content Skip to Search
Product Documentation

Combining Buses into an Array of Buses

What Is an Array of Buses?

An array of buses is an array whose elements are buses. Each element in an array of buses must be nonvirtual and must have the same bus type. (That is, each bus object has the same signal name, hierarchy, and attributes for its bus elements).

An example of using an array of buses is to model a multi-channel communication system. You can model all the channels using the same bus object, although each of channels could have a different value.

Using arrays of buses involves:

To see an example of a model that uses an array of buses, open the sldemo_bus_arrays demo. In this demo, the nonvirtual bus input signals connect to a Concatenate block that creates an array of bus signals. When you update the diagram, the demo model looks like the following figure:

The model uses the array of buses with:

For additional background about when to use arrays of buses, see:

For details about working with an array of buses, see:

For information about converting an existing model to use an array of buses, see Converting a Model to Use an Array of Buses.

Benefits of an Array of Buses

Using an array of buses allows you to replace buses of arrays and buses of identical buses. Using an array of buses provides these benefits:

Blocks That Support Arrays of Buses

The following blocks support arrays of buses:

For requirements for using some of these blocks with arrays of buses, see Block Limitations.

Using Arrays of Buses with Bus-Related Blocks

To select a signal within an array of buses, first use a Selector block to find the appropriate bus within the vector. Then use a Bus Selector block to select the signal.

To assign to a signal within an array of buses, first use a Bus Assignment block to assign to a bus element. Then use the Assignment block to assign the bus to the vector.

Bus Selector and Bus Assignment blocks can only accept scalar buses, no arrays of buses.

A Bus Creator block can accept an array of buses as input, but you cannot used a Bus Creator block to create array of buses output.

Array of Buses Limitations

Bus Limitations

The buses that you combine into an array must all:

Structure Parameter Limitations

The following limitations apply to using structure parameters with an array of buses.

You can use:

You cannot use:

For more information, see Specifying Initial Conditions for Bus Signals.

Set Strict Bus Handling Diagnostic to Error

Before you run simulation on a model that uses an array of buses, in the Configuration Parameters > Diagnostics > Connectivity pane, set Mux blocks used to create bus signals to error.

Block Limitations

The following table describes the block parameter setting limitations for blocks that support arrays of buses. This information is also in the reference pages for each of these blocks.

For limitations for bus-related blocks, see Using Arrays of Buses with Bus-Related Blocks.

BlockBlock Parameters Limitations
Memory

Initial condition — Only this parameter (which may be, but does not have to be, a structure) is scalar-expanded to match the dimensions of the array of buses.

Merge
  • Allow unequal port widths — Clear this parameter.

  • Number of inputs — Set to a value of 2 or greater.

  • Initial condition — Only this parameter (which may be, but does not have to be, a structure) is scalar-expanded to match the dimensions of the array.

Multiport Switch

Number of data ports — Set to a value of 2 or greater.

Signal Conversion

Output — Set to Signal copy.

Switch

Threshold — Specify a scalar threshold.

Simulink Feature Limitations

You cannot:

Stateflow Limitations

Stateflow action language does not support arrays of buses.

Defining an Array of Buses

For information about the kinds of buses that you can combine into an array of buses, see Bus Limitations.

Using a Concatenate Block to Define an Array of Buses

To define an array of buses, use a Concatenate block. The table describes the array of buses input requirements and output for each of the Vector Concatenate and the Matrix Concatenate versions of the Concatenate block.

BlockBus Signal Input RequirementOutput
Vector Concatenate

Vectors, row vectors, or columns vectors

If any of the inputs are row or column vectors, row or column vector

Matrix Concatenate

Signals of any dimensionality (scalars, vectors, and matrices)

Trailing dimensions are assumed to be 1 for lower dimensionality inputs.

Concatenation is on the dimension that you specify with the Concatenate dimension parameter.

To use a Concatenate block to define an array of buses, see How to Define an Array of Buses.

How to Define an Array of Buses

  1. Define one bus object to use for all the bus signals that you want to combine into an array of buses. For information about defining bus objects, see Creating Bus Objects.

    The sldemo_bus_arrays demo defines an sldemo_bus_arrays_busobject bus object, which the Bus Creator blocks use for the input bus signals (Scalar Bus) for the array of buses.

  2. Add a Vector Concatenate or Matrix Concatenate block to the model and open the block parameters dialog box for the block.

    The sldemo_bus_arrays_busobject demo uses a Vector Concatenate block, because the inputs are scalars.

  3. Set the Number of inputs parameter to be the number of buses that you want to be in the array of buses.

    The block icon displays the number of input ports that you specify.

  4. Set the Mode parameter to match the type of the input bus data.

    In the sldemo_bus_arrays demo, the input bus data is scalar, so the Mode setting is Vector.

  5. If you use a Matrix Concatenation block, set the Concatenate dimension parameter to specify the output dimension along which to concatenate the input arrays. Enter one of the following values:

    • 1 to concatenate input arrays vertically

    • 2 to concatenate input arrays horizontally

    • A higher dimension than 2, to perform multidimensional concatenation on the inputs

  6. Connect the buses that you want to be in the array of buses to the Concatenate block.

Signal Line Style for an Array of Buses

After you create an array of buses and update the diagram, the line style for the array of buses signal is a thicker version of the signal line style for a nonvirtual bus signal.

For example, in the sldemo_bus_arrays demo, the Scalar Bus signal is a nonvirtual bus signal, and the Bus Array output signal of the Concatenate block is an array of buses signal.

Using an Array of Buses in a Model

A General Workflow for Using an Array of Buses in a Model

Setting up a model to use an array of buses usually involves basic tasks similar to these:

  1. Define the array of buses, as described in Defining an Array of Buses.

  2. Add a subsystem for performing iterative processing on each element of the array of buses. For example, use a For Each Subsystem block or an Iterator block. See Performing Iterative Processing with an Array of Buses.

  3. Connect the array of buses signal from the Concatenate block to the iterative processing subsystem that you set up in step 2.

  4. Model your scalar algorithm within the iterative processing subsystem (for example, a For Each subsystem). Operate on the array first (using Selector and Assignment blocks), and then use the Bus Selector and Bus Assignment blocks to select elements from, or assign elements to, a scalar bus within the subsystem.

This simplified picture reflects the general workflow described above.

Performing Iterative Processing with an Array of Buses

You can perform iterative processing on the bus signal data of an array of buses using blocks such as a For Each Subsystem block, a While Iterator Subsystem block, or a For Iterator Subsystem block. You can use one of these blocks to perform the same kind of processing on each bus in the array of buses, or a selected subset of buses in the array of buses.

Assigning Into an Array of Buses

Use an Assignment block to assign values to specified elements in a bus array.

For example, in the sldemo_bus_arrays demo, the Assignment block assigns the value to the first element of the array of buses. The block parameters dialog box looks like the following graphic:

To assign bus elements within a bus signal, use the Bus Assignment block. The input for the Bus Assignment block must be a scalar bus signal.

Selecting Bus Elements from an Array of Buses

Use a Selector block to select elements of an array of buses. The input array of buses can be of any dimensionality.

The output bus signal of the Selector block is a selected or reordered set of elements from the input array of buses.

For example, the sldemo_bus_arrays demo uses Selector blocks to select elements from the array of buses signal that the Assignment and For Each Subsystem blocks outputs. The block parameters dialog box for the Selector block that selects the first element looks like the following graphic:

To select bus elements within a bus signal, use the Bus Selector block. The input for the Bus Selector block must be a scalar bus signal.

Generated Code for an Array of Buses

When you generate code for a model that includes an array of buses, a typedef that represents the underlying bus type appears in the *_types.h file.

Code generation produces an array of C structures that you can integrate with legacy C code that uses arrays of structures. As necessary, code for bus variables (arrays) are generated in the following structures:

Here is a simplified example of some generated code for an array of buses.

Converting a Model to Use an Array 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:

General Workflow for Converting a Model to Use an Array of Buses

This section presents a general guide to 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 Combining Buses into an Array 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 construction in the original modeling pattern is inefficient for two reasons:

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 Vector Concatenate or Matrix 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.

    For limitations, see the For Each Subsystem block documentation; for example, the scalar algorithm within the For-Each subsystem cannot have continuous states.

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

 © 1984-2012- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS