Virtual and Nonvirtual Buses

About Virtual and Nonvirtual Buses

A bus signal can be virtual, meaning that it is just a graphical convenience that has no functional effect, or nonvirtual, meaning that the signal occupies its own storage.

Bus Signal Lines

When you simulate a model that contains buses, Simulink uses different line styles for virtual and nonvirtual bus signals.

Virtual Bus
Nonvirtual Bus

Bus Storage

During simulation:

  • A block connected to a virtual bus reads inputs and writes outputs by accessing the memory allocated to the component signals. These signals are typically noncontiguous, and no intermediate memory exists.

  • A block connected to a nonvirtual bus reads inputs and writes outputs by accessing copies of the component signals. The copies are maintained in a contiguous area of memory allocated to the bus.

Compared with nonvirtual buses, virtual buses reduce memory requirements because they do not require a separate contiguous storage block, and execute faster because they do not require copying data to and from that block.

A nonvirtual bus is represented by a structure in generated code, which can be helpful when tracing the correspondence between the model and the code.

Choose Between Virtual and Nonvirtual Buses

Whether to use a virtual or nonvirtual bus depends on your modeling goal. Frequently, a model contains both virtual and nonvirtual buses.

Modeling GoalType of Bus

Use bus signals within a functional unit, such as within a referenced model


Use signals with different sample rates in a bus

Virtual (required)

Have bus data packaged as data structures in the generated code


Have bus signals cross model reference boundaries

Virtual or nonvirtual

For nonvirtual buses, consider stripping out unneeded data from bus objects crossing model reference boundaries. In large models, bus objects can become quite large and have several levels of hierarchy. Often referenced models need some, but not all, of the data contained in large buses. Passing unneeded data across model reference boundaries impacts performance negatively. The interface definition for a model should specify exactly what data the model uses.

Use a bus object to define the data type for the root-level Inport and Outport blocks.

Have bus data cross MATLAB Function block or Stateflow® chart boundaries


Interface with external code either through an S-function or the Legacy Code Tool


Not all blocks can accept buses. See Bus-Capable Blocks for more about which blocks can handle which types of buses. Virtual buses are the default except where nonvirtual buses are explicitly required. See Use Buses for Inports and Outports for more information.

In general, virtual buses do not affect the generated code. You can optionally use nonvirtual buses to group signals into structures in the generated code. For additional guidelines for generated code for nonvirtual buses, see Group Signals into Structures in the Generated Code Using Buses.

Nonvirtual Bus Sample Times

All signals in a nonvirtual bus must have the same sample time, even if the elements of the associated bus object specify inherited sample times. Any bus operation that would result in a nonvirtual bus that violates this requirement generates an error.

All buses and signals input to a Bus Creator block that outputs a nonvirtual bus must therefore have the same sample time. You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus, to allow the signal or bus to be included in a nonvirtual bus.

Automatic Bus Conversion

When updating a diagram prior to simulation or code generation, Simulink® automatically converts a virtual bus to a nonvirtual bus (or vice versa) in cases such as when the virtual bus is an input to, or output from:

  • An S-Function block

  • A Stateflow chart

When you pass a bus signal into a referenced model, Simulink makes the bus a virtual or nonvirtual bus to match the type of bus specified for the Inport block it feeds. Bus signal outputs are virtual or nonvirtual, based on the specification for the Outport block. For bus signals driving a root-level Outprt block, Simulink performs a similar conversion. For more information, see Bus Data Crossing Model Reference Boundaries.

The conversion consists of inserting hidden Signal Conversion blocks into the model where needed. Conversion to a nonvirtual bus fails if no bus object is specified at the port to which the virtual bus connects.

Explicit Bus Conversion

You can eliminate the need for the automatic conversion by using one of these approaches:

  • Specify a nonvirtual bus in the block where the bus originates. For example, if you use a Bus Creator block to create a bus, then to specify a nonvirtual bus, set the Bus Creator block Data type parameter to use a Simulink.Bus object.

  • Manually insert a Signal Conversion block. Using a Signal Conversion block can reduce memory usage, support modeling constructs such as Model blocks that require that input buses be nonvirtual, and reduce generated code. For details, see the Signal Conversion documentation.

See Also



Related Examples

More About

Was this topic helpful?