Correct Buses Used as Muxes

Three Approaches

The three approaches that you can use to correct bus signals used as muxes are:

Generally, using the Model Advisor is the most efficient approach.

Use the Model Advisor

Before you use the Model Advisor to correct bus signals used as muxes, perform the steps described in Correct Mux Blocks That Create Bus Signals.

  1. Open the Model Advisor from the Upgrade Advisor, or in the Simulink® Editor, select Analysis > Model Advisor > Model Advisor.

  2. Select and run the Simulink > Check bus usage check.

    The Model Advisor reports any cases of bus signals treated as muxes.

  3. Follow the Model Advisor suggestions for correcting errors reported by the check.

For additional information about using the Model Advisor, see Consulting the Model Advisor.

Explicitly Add Bus to Vector Blocks

You can explicitly add Bus to Vector blocks to convert the bus signal to a mux (vector), using one of these approaches:

  • To explicitly convert the bus to a mux (vector), insert the Bus to Vector block into any bus used implicitly as a mux.

  • Use the Simulink.BlockDiagram.addBusToVector function, which automatically inserts Bus to Vector blocks wherever needed.

For example, this model uses a bus signal as a mux signal by using the bus as an input to a Gain block. The Scope block shows the simulation results.

This figure shows the same model, rebuilt after inserting a Bus to Vector block after the Bus Creator block.

The results of simulation are the same in either case. The Bus to Vector block is virtual, and does not affect simulation results, code generation, or performance.

Reorganize the Model

You can replace blocks manually to avoid using bus signals as muxes. Change the sources for a block that require vector inputs to avoid feeding a bus signal into a block that requires vector input.

For example, in the following model, the Gain block requires a vector signal. However, the input signal is a bus signal created by a Bus Creator block.

Change the Bus Creator block to a Mux block to provide the required vector signal for the Gain block.

Challenges with reorganizing the model manually include:

  • Identifying all the occurrences in a model. (The Model Advisor check identifies all occurrences in the model and helps you to correct them.)

  • Dealing with many occurrences in a model is time-consuming and error-prone.

  • Reorganizing the model to address this issue can interfere with other aspects of the model.

Bus to Vector Block Compatibility Issues

If you use Save As to save a model in a version of the Simulink product before R2007a (V6.6), Simulink:

  • Sets the StrictBusMsg parameter to error if its value is WarnOnBusTreatedAsVector or ErrorOnBusTreatedAsVector.

  • Replaces each Bus to Vector block in the model with a null subsystem that outputs nothing.

The resulting model specifies strong type checking for Mux blocks used to create buses. Before you can use the model, reconnect or otherwise correct each signal that contained a Bus to Vector block but is now interrupted by a null subsystem.

Related Examples

More About

Was this topic helpful?