Main Content

Group Nonvirtual Buses in Arrays of Buses

An array of buses is an array whose elements are nonvirtual buses defined by the same Simulink.Bus object. An array of buses is equivalent to a MATLAB® array of structures.

Use an array of buses to:

  • Reduce maintenance by centralizing algorithms used for processing multiple buses.

  • Streamline iterative processing of multiple buses of the same type, for example, by using a for-each subsystem with the array of buses.

  • Change the number of buses being processed without having to restructure the parts of the model that use the array of buses.

  • Use built-in blocks, such as the Assignment or Selector blocks, to manipulate arrays of buses just like arrays of any other type. Using an array of buses avoids the need for you to create custom S-functions to manage packing and unpacking structure signals.

  • Generate code that has an array of C structures, which you can integrate with legacy C code that uses arrays of structures. This approach simplifies indexing into an array for Simulink® computations, using a for loop on indexed structures.

For example, you can model a multi-channel system, such as a communications system, as an array of buses. While all the channels have the same properties, each of the channels may have a different value.


To create a reusable specification for an array of buses, define a Simulink.ValueType object with DataType set to a Simulink.Bus object and Dimensions set to the dimensions of the array.

For a model that demonstrates multiple ways to use an array of buses, see Model Arrays of Buses.

Arrays of buses with variable-size signals are supported, subject to certain limitations. See Variable-Size Signal Limitations.

Requirements of Arrays of Buses

All buses combined into an array of buses must:

  • Be nonvirtual

  • Specify the same Simulink.Bus object data type (that is, the same name, hierarchies, and bus element attributes)

For information on creating nonvirtual buses, see Create Nonvirtual Buses.

For information on which blocks support arrays of buses, see Bus-Capable Blocks.

Create Array of Buses from Nonvirtual Buses

You can use a Vector Concatenate or Matrix Concatenate block to group nonvirtual buses into an array of buses. Simulink treats nonvirtual buses as scalars. Therefore, you can use either of these blocks regardless of the bus element data types.

To create an array of buses with one of these blocks:

  1. Define one Simulink.Bus object data type for all of the nonvirtual buses that you want to group in the array of buses.

  2. In the Block Parameters dialog box for the Vector Concatenate or Matrix Concatenate block, set Number of inputs to the number of buses you want in the array of buses. The block icon displays the number of input ports that you specify.

  3. Connect the nonvirtual buses to the block inputs.

The block output is the array of buses.

Open and compile the example model. To compile the model, on the Modeling tab of the Simulink Toolstrip, click Update Model or Run. Compiling the model updates the line styles, which you can use to visually identify arrays of buses.

To demonstrate how to create arrays of buses from nonvirtual buses, the model uses:

  • Two Bus Creator blocks to create two nonvirtual buses that have the same Bus object data type (Bus: BusObject).

  • A Vector Concatenate block with Number of inputs set to 2 to group the two nonvirtual buses in an array of buses.

To demonstrate how to select elements from the array of buses, the model uses:

  • A Selector block to extract one of the buses from the array of buses based on the specified Index in the dialog box. Because arrays of buses are concatenated signals that provide index-based access to their elements, the Selector block uses Index vector (dialog) for the Index Option.

  • A Bus Selector block to extract the elements of the nonvirtual bus using name-based access.

The Signal Dimensions information overlay shows that the array of buses contains two buses. To enable the Signal Dimensions overlay, in the Simulink Toolstrip, on the Debug tab, select Information Overlays > Signal Dimensions.

Create Array of Buses from MATLAB Structures

You can use a Constant block to compactly represent an array of buses with constant-valued bus elements. This technique can reduce the number of lines in a model and the number of variables used by the model, especially when the model repeats an algorithm with different parameter values.

On the Constant block, specify:

  • Constant value as an array of MATLAB structures or a Simulink.Parameter object that specifies an array of MATLAB structures

  • Output data type as a Simulink.Bus object

Constant blocks only support MATLAB® structures when the output data type is a Bus object.

Define an array of structures named const_struct_array. Compose each structure of the same elements: Offset, Gain, and Threshold.

const_struct_array(1).Offset = 197;
const_struct_array(1).Gain = 4.32;
const_struct_array(1).Threshold = 795.68;

const_struct_array(2).Offset = 158;
const_struct_array(2).Gain = 3.83;
const_struct_array(2).Threshold = 1039.77;

To create an array of structures for a bus hierarchy with many elements, consider using the Simulink.Bus.createMATLABStruct function.

Define the corresponding Bus object data type.


The new Bus object uses the default name slBus1.

Open and simulate the example model, which contains a Constant block with Constant value set to const_struct_array and Output data type set to Bus: slBus1.


The output of the Constant block is an array of buses.

The For Each Subsystem block iteratively processes the constant values for each nonvirtual bus in the array. The subsystem contents display the nonvirtual bus instead of the array of buses that connects to the port.

See Also


Related Topics