Combine Buses into an Array of Buses

    Tip   Simulink® provides several techniques for combining signals into a composite signal. For a comparison of techniques, see Techniques for Combining Signals.

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. 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 of the channels using the same bus object, although each of the channels could have a different value.

Using arrays of buses involves:

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

The model uses the array of buses with:

  • An Assignment block, to assign a bus in the array

  • A For Each Subsystem block, to perform iterative processing over each bus in the array

  • A Memory block, to output the array of buses input from the previous time step

Benefits of an Array of Buses

Using an array of buses:

  • Represents structured data compactly

    • Reduces model complexity

    • Reduces maintenance by centralizing algorithms used for processing multiple buses

  • Streamlines iterative processing of multiple buses of the same type, for example, by using a For Each Subsystem with the array of buses

  • Simplifies changing the number of buses, without your having to restructure the rest of the model or make updates in multiple places in the model

  • Allows models to use built-in blocks, such as the Assignment or Selector blocks, to manipulate arrays of buses just like arrays of any other type, rather than your creating custom S-functions to manage packing and unpacking structure signals

  • Supports using the combined bus data across subsystem boundaries, model reference boundaries, and into or out of a MATLAB Function block

  • Allows you to keep all the logic in the Simulink model, rather than splitting the logic between C code and the Simulink model

    • Supports integrated consistency and correctness checking, maintaining metadata in the model, and avoids your keeping track of model components in two different environments

  • Generates code that has an array of C structures, which you can integrate with legacy C code that uses arrays of structures

    • Simplifies indexing into an array for Simulink computations, using a for loop on indexed structures

Array of Buses Limitations

Bus Limitations

The buses combined into an array must all:

  • Be nonvirtual

  • Have the same bus type (that is, same name, hierarchies, and attributes for the bus elements)

  • Have no variable-size signals or frame-based signals

Supported Blocks

You can use arrays of buses with the following blocks:

  • Virtual blocks

  • Several nonvirtual blocks, such as:

    • Some signal routing blocks (for example, Data Store Memory, Merge, and Switch)

    • Rate Transition and Zero-Order Hold blocks

  • Several additional blocks, such as Assignment, MATLAB Function, and Signal Conversion

For a complete list, see Blocks That Support Arrays of Buses. That section describes requirements for using the supported blocks.

Structure Parameter Limitations

To initialize an array of buses with structure parameters, you can use:

  • The number 0. In this case, all of the individual signals in the array of buses use the initial value 0.

  • A scalar struct that represents the same hierarchy of fields and field names as the bus type. In this case, the scalar structure expands to initialize each of the individual signals in the array of buses.

  • An array of structures that specifies an initial value for each of the individual signals in the array of buses.

You cannot use partial structures.

If you use an array of structures, all of the structures in the array must have the same hierarchy of fields. Each field in the hierarchy must have the same characteristics across the array:

  • Field name

  • Numeric data type, such as single or int32

  • Complexity

  • Dimensions

For more information about specifying initial conditions for bus signals, see Specify Initial Conditions for Bus Signals.

Signal Logging Limitation

Simulink does not log signals inside referenced models in Rapid Accelerator mode.

Stateflow Limitations

Stateflow® action language does not support arrays of buses.

Define an Array of Buses

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

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, output is a 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.

    Note:   Do not use a Mux block or a Bus Creator block to define an array of buses. Instead, use a Bus Creator block to create scalar bus signals.

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

    The sldemo_bus_arrays model defines an sldemo_bus_arrays_busobject bus object, which both of 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's parameters dialog box.

    The sldemo_bus_arrays_busobject model 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 model, 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 — concatenate input arrays vertically

    • 2 — concatenate input arrays horizontally

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

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

Related Examples

Was this topic helpful?