When a block that requires a vector input receives a bus input, the bus is implicitly treated as a vector. Configuring a model to avoid using buses as vectors:
Improves loop handling
Contributes to consistent edit and compile-time behavior
When correcting buses used as vectors, the Model Advisor generally provides the most efficient approach.
In the Simulink® Editor, select Analysis > Model Advisor > Model Advisor.
Select and run the Simulink Check bus signals treated as vectors check.
The Model Advisor reports any cases of buses treated as vectors.
Follow the Model Advisor suggestions for correcting errors reported by the check.
For additional information about using the Model Advisor, see Select and Run Model Advisor Checks.
To explicitly convert a bus to a mux (vector), add Bus to Vector blocks using one of these approaches:
Insert the Bus to Vector block into buses treated as vectors.
Simulink.BlockDiagram.addBusToVector function, which
automatically inserts Bus to Vector blocks where buses are
treated as vectors.
For example, model
ex_bus_to_vector treats buses as vectors by
using the buses as inputs to Gain blocks.
This figure shows the same model with Bus to Vector blocks after the Bus Creator block.
The Scope block shows the simulation results.
The simulation results are the same in either case. The Bus to Vector block is virtual, and does not affect simulation results, code generation, or performance.
To avoid feeding a bus into a block that requires a vector input, you can manually replace the source for a block that requires vector inputs.
For example, in model
ex_bus_to_vector, the Gain
block requires a vector signal. However, the input signal is a bus created by a
Bus Creator block.
To provide the required vector signal for the Gain block, replace the Bus Creator block with a Mux block.
Reorganizing the model manually poses these challenges:
Identifying all occurrences in a model can be difficult.
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.
To identify buses treated as vectors:
Use the Model Advisor Check bus signals treated as vectors check.
Set configuration parameter Bus signal treated as
error. The default setting for Bus
signal treated as vector is
which generates no warning or error message when a block implicitly
converts a bus to a vector during simulation.