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, seeBus to Vector.
识别隐含Bus-to-Vector转换
Open and simulate modelex_bus_to_vector
.
To accept the bus, the Gain blocks implicitly convert the bus to a vector.
To identify buses treated as vectors before simulation, use functionSimulink.BlockDiagram.addBusToVector
.
[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 theBus signal treated as vectorconfiguration parameter towarning
orerror
. The default setting forBus signal treated as vectorisnone
, 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 functionSimulink.BlockDiagram.addBusToVector
withreportOnly
set tofalse
. When you use functionSimulink.BlockDiagram.addBusToVector
withreportOnly
set tofalse
, the function saves the model. To create a writable copy of modelex_bus_to_vector
, this example uses thesave_system
function.
save_system('ex_bus_to_vector','ex_bus_to_vector_blocks');
[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.
FunctionSimulink.BlockDiagram.addBusToVector
返回s 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 parameterBus signal treated as vectorset towarning
orerror
alerts you when an unexpected bus-to-vector conversion occurs.