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.

Simulation Results and Generated Code

For a virtual bus, simulation results and generated code are exactly the same as if the bus did not exist, which functionally it does not.

Generated code for a nonvirtual bus represents the bus data with a structure. The use of a structure in the generated code can be helpful when tracing the correspondence between the model and the code. For example, below is the generated code for Bus Creator block in the ex_bus_logging model.

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 units, 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 data cross model reference, MATLAB Function block, or Stateflow® chart boundaries


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.

For additional guidelines for generated code for buses, see About Buses and Code Generation.

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:

  • A referenced model

  • An S-Function block

  • A Stateflow chart

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.

Related Examples

Was this topic helpful?