Manage Bus-to-Vector Conversions
This example shows how to find and manage implicit bus-to-vector conversions.
Blocks that do not accept buses may implicitly convert buses to vectors. When a bus is treated as a vector, bus elements become inaccessible.
Some buses cannot convert to vectors. For more information, see Bus to Vector.
Identify Implicit Bus-to-Vector Conversions
Open and simulate model
To accept the bus, the Gain blocks implicitly convert the bus to a vector.
To identify buses treated as vectors before simulation, use function
[blocks] = Simulink.BlockDiagram.addBusToVector('ex_bus_to_vector')
### Processing block diagram 'ex_bus_to_vector' ### Number of blocks left that are connected to a bus being used as a vector: 2 ### Done processing block diagram 'ex_bus_to_vector' blocks = 1x2 struct array with fields: BlockPath InputPort LibPath
To identify buses treated as vectors during simulation, set the Bus signal treated as vector configuration parameter to
error. The default setting for Bus signal treated as vector is
none, which generates no warning or error message when a block implicitly converts a bus to a vector.
Explicitly Define Bus-To-Vector Conversions
To insert Bus to Vector blocks where blocks implicitly convert buses to vectors, use function
reportOnly set to
false. When you use function
reportOnly set to
false, the function saves the model. To create a writable copy of model
ex_bus_to_vector, this example uses the
[blocks,busToVectors] = Simulink.BlockDiagram.addBusToVector('ex_bus_to_vector_blocks',true,false);
The Gain blocks no longer implicitly convert the bus to a vector. The inserted Bus to Vector blocks perform the conversion explicitly.
Bus to Vector blocks are virtual and do not affect simulation results, code generation, or performance.
Simulink.BlockDiagram.addBusToVector returns no remaining implicit bus-to-vector conversions.
[blocks] = Simulink.BlockDiagram.addBusToVector('ex_bus_to_vector_blocks')
###No buses used as vectors left to process blocks = 1x0 empty struct array with fields: BlockPath InputPort MixedAttributes
By specifying acceptable bus-to-vector conversions with Bus to Vector blocks, you can more easily identify unexpected conversions. Having configuration parameter Bus signal treated as vector set to
error alerts you when an unexpected bus-to-vector conversion occurs.