An array of buses is an array whose elements are nonvirtual buses.
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
For example, you can model a multi-channel system, such as a communications system, as an array of buses. All the channels have the same data type, and each of the channels can have a different value.
For a model that demonstrates multiple ways to use an array of buses, see Model Arrays of Buses.
All buses combined into an array of buses must:
Specify the same
Simulink.Bus object data
type (that is, the same name, hierarchies, and bus element
Have no variable-size signals or frame-based signals
For information on creating nonvirtual buses, see Create Nonvirtual Buses.
For information on which blocks support arrays of buses, see Bus-Capable Blocks.
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:
Simulink.Bus object data type for all of the nonvirtual buses that you want to group in the array of buses.
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.
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:
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.
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
Constant blocks only support MATLAB® structures when the output data type is a
Define an array of structures named
const_struct_array. Compose each structure of the same elements:
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
Define the corresponding
Bus object data type.
Bus object uses the default name
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
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.