| Contents | Index |
| On this page… |
|---|
Blocks That Support Arrays of Buses Using an Array of Buses in a Model |
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:
Using a bus object as a data type (See Specifying a Bus Object Data Type.)
Working with arrays (See Matrices and Arrays
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:
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
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.
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:
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
Makes it easier for you to change 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
Generated code has an array of C structures that you can integrate with legacy C code that uses arrays of structures:
Makes it easier to index into an array for Simulink computations, using a for loop on indexed structures
The following blocks support arrays of buses:
Virtual blocks (see Virtual Blocks)
These nonvirtual blocks:
Two-Way Connection (a Simscape block)
For requirements for using some of these blocks with arrays of buses, see Block Limitations.
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.
The buses that you combine 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
The following limitations apply to using structure parameters with an array of buses.
You can use:
0 as an initial condition for an array of buses
A scalar struct that represents the same hierarchy and names as the array of buses
You cannot use:
Partial structures
An array of structures
A structure parameter for an array of buses that has an element that is an array of buses
For more information, see Specifying Initial Conditions for Bus Signals.
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.
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.
| Block | Block 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 |
|
| 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. |
You cannot:
Log an array of buses signal
Import data from or export data to an array of buses.
Stateflow action language does not support arrays 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.
| Block | Bus Signal Input Requirement | Output |
|---|---|---|
| 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.
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. |
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.
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.
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.
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.
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
Connect the buses that you want to be in the array of buses to the Concatenate block.
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.

Setting up a model to use an array of buses usually involves basic tasks similar to these:
Define the array of buses, as described in Defining an Array of Buses.
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.
Connect the array of buses signal from the Concatenate block to the iterative processing subsystem that you set up in step 2.
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.

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.
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.
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.
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:
Block IO
States
External inputs
External outputs
Here is a simplified example of some generated code for 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:
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.
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 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:
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.
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).
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.
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.
![]() | Specifying Initial Conditions for Bus Signals | Buses and Libraries | ![]() |

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 |