Choose the composite signal technique that meets your modeling requirements. For background information about each technique, see Composite Signal Techniques.
Use virtual buses to reduce signal clutter in a block diagram. In general, using a virtual bus is simpler and can be more efficient than using a nonvirtual bus. However, some modeling features require nonvirtual buses, such as bus data that crosses MATLAB Function block or Stateflow® chart boundaries. For example, use a virtual bus for bus signals that:
Have bus elements that have different sample rates
Cross model reference boundaries, if the referenced model only uses a few of the bus elements.
Compared with nonvirtual buses, virtual buses reduce memory requirements. Virtual buses do not require a separate contiguous storage block. During simulation, virtual buses execute faster because they do not require copying data to and from that block. The generated code also executes faster for virtual buses than for nonvirtual buses.
Use nonvirtual buses to:
Display and log bus signals with a Scope block.
Construct an array of buses.
Have bus data cross MATLAB Function block or Stateflow chart boundaries.
Interface with external code through an S-function.
Package bus data as structures in the generated C code.
Generated code represents a nonvirtual bus as a structure. The structure can be helpful for tracing the correspondence between the model and the code. Generated code for nonvirtual buses can result in multiple copies of some bus signals. For an example of the difference in generated code for virtual and nonvirtual buses, see Generate Code for Buses. For additional guidelines for generating code for nonvirtual buses, see Organize Data into Structures in Generated Code (Simulink Coder).
All signals in a nonvirtual bus input to a block must use the same sample time, even if the elements of the associated bus object specify inherited sample times. You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus.
For models that include bus signals composed of many bus elements that feed subsystems, consider using the In Bus Element and Out Bus Element blocks. You can use these bus element port blocks instead of Inport with Bus Selector blocks for inputs, and Outport with Bus Creator blocks for outputs. These bus element port blocks:
Reduce signal line complexity and clutter in a block diagram.
Make it easier to change the interface incrementally.
Allow access to a bus element closer to the point of usage, avoiding the use of a Bus Selector and Goto block configuration.
For example, here is a model that uses Inport, Bus Selector, Bus Creator, and Outport blocks.
Here is an equivalent model that uses bus element port blocks.
Consider using bus element ports for models with bus signals that you anticipate changing frequently during the model development process.
Bus element port blocks have these restrictions:
The Out Bus Element output bus is a virtual bus.
Bus objects associated with signals used with bus element port blocks are ignored.
You cannot specify the underlying Inport or Outport block specifications, such as word length.
You can refactor a subsystem interface that uses Inport, Bus Selector, Bus Creator, and Outport blocks to use In Bus Element and Out Bus Element blocks. Conversion operations are supported only when the signal lines or blocks do not have any extra specification. You can use single-click operations to:
Convert Inport and Bus Selector blocks in a subsystem to In Bus Element blocks.
Convert Outport and Bus Creator blocks in a subsystem to Out Bus Element blocks.
Transform input or output interfaces of subsystems to use bus element port blocks.
For more information, see Simplify Subsystem Bus Interfaces.
Combine multiple nonvirtual buses into an array. An array of buses is equivalent to an array of structures in MATLAB®. An example of using an array of buses is to model a multi-channel system. You can model all the channels using the same bus object, although each of the channels can have a different value.
Each element in an array of buses must be nonvirtual and must have the same bus object. Each bus object has the same signal name, hierarchy, and attributes for its bus elements. Arrays of buses require the use of bus objects. For details, see Combine Buses into an Array of Buses.
To combine signals of same type into a vector, you can use a Mux block. A mux is a special kind of noncontiguous (virtual) vector. You can use a mux anywhere that you could use an ordinary (contiguous) vector. For example, you can perform calculations on a mux. The computation affects each constituent value in the mux, as if the values existed in a contiguous vector. Using a mux to perform computations on multiple vectors avoids the overhead of copying the separate values to contiguous storage. Also, you can use a Mux block to create a vector of function calls.
To combine a vector or matrix, you can use a Vector Concatenate or Matrix Concatenate block. These blocks are useful for creating an output signal that is contiguous.
If you want index-based access, use a Mux block. For name-based access, use a bus.
You can combine a vector or matrix by using a Vector Concatenate or Matrix Concatenate block. These blocks are useful for creating an output signal that is contiguous. You can use this concatenation in mathematical operations. For examples of using these blocks, see the Vector Concatenate and Matrix Concatenate block documentation.