Documentation

Simulink.BlockDiagram.addBusToVector

Convert virtual bus signals into vector signals by adding Bus to Vector blocks

Syntax

[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model)
[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model,includeLibs)
[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model,includeLibs,reportOnly)
[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model,includeLibs,reportOnly,strictOnly)

Description

[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model) searches a model, excluding any library blocks, for bus signals used implicitly as vectors, and returns the results of the search.

[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model,includeLibs) searches a model, and if includeLibs is true, includes in the search library blocks for bus signals used implicitly as vectors.

example

[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model,includeLibs,reportOnly) searches a model, and if reportOnly is set to false, then the function inserts a Bus to Vector block into each bus that is used as a vector in any block that it searches. The insertion replaces the implicit use of a bus as a vector with an explicit conversion of the bus to a vector. The source and destination blocks of the signal do not change.

If Simulink.BlockDiagram.addBusToVector adds Bus to Vector blocks to the model or any library, the function changes the saved copy of the diagram.

If Simulink.BlockDiagram.addBusToVector changes a library block, the change affects every instance of that block in every model that uses the library.

example

[destBlocks,busToVectorBlocks,ignoredBlocks] = Simulink.BlockDiagram.addBusToVector(model,includeLibs,reportOnly,strictOnly) searches a model, and if strictOnly is true, the function checks for input bus signals used implicitly as vectors that are fed into one of these blocks. These blocks cannot take virtual bus signals, but they can accept nonvirtual bus signals.

  • Delay

  • Selector

  • Assignment

  • Vector Concatenate

  • Reshape

  • Permut Dimensions

Examples

collapse all

The ex_bus_to_mux_ng model simulates correctly, but the input to the Gain block is a bus, while the output is a vector. Therefore, the Gain block uses a bus signal as a vector.

Open the model.

open_system(fullfile(matlabroot,'examples','simulink',...
'ex_bus_to_mux_ng'))

Insert a Bus to Vector block to convert the bus input signal for the Gain block to a vector signal because the Gain block can accept only non-bus signals.

[blocks,busToVectors] = Simulink.BlockDiagram.addBusToVector(...
'ex_bus_to_mux_ng',true,false)
### Processing block diagram 'ex_bus_to_mux_ng'
### Number of blocks left that are connected to a bus being used as a vector: 1
### Successfully inserted Bus to Vector Blocks in model. Preparing to save model and/or libraries
### To eliminate modeling errors in the future, please enable strict bus modeling by setting the 'Bus signal treated as vector' diagnostic in the Configuration parameter dialog, Diagnostic/Connectivity tab to 'error'
### Done processing block diagram 'ex_bus_to_mux_ng'

blocks = 

  struct with fields:

    BlockPath: 'ex_bus_to_mux_ng/Gain'
    InputPort: 1
      LibPath: ''


busToVectors =

  cell

    'ex_bus_to_mux_ng/Bus to Vector'

The Gain block no longer implicitly converts the bus to a vector. The inserted Bus to Vector block performs the conversion explicitly. The results of simulation are the same for both models. The Bus to Vector block is virtual and does not affect simulation results, code generation, or performance.

Input Arguments

collapse all

Model name or handle, specified as a character vector.

Search library blocks, specified as false or true.

  • false — Search only the blocks in the model.

  • true — Search library blocks for bus signals used implicitly as vectors.

Specify as the second argument.

Data Types: logical

Choice to report results without changing the model, specified as false or true.

  • false — Update the model by inserting Bus to Vector blocks for bus signals that are implicitly used as vectors.

  • true — Report search results, but do not change the model.

Specify as the third argument (you must also specify the model and includeLibs arguments).

Data Types: logical

Check input bus signals used implicitly as vectors that feed blocks that can accept nonvirtual, but not virtual, bus signals, specified as false or true. If strictOnly is true, the function checks for input bus signals used implicitly as vectors that are fed into one of these blocks. These blocks cannot take virtual bus signals, but they can accept nonvirtual bus signals.

  • Delay

  • Selector

  • Assignment

  • Vector Concatenate

  • Reshape

  • Permut Dimensions

Specify as the foruth argument (you must also specify the model and includeLibs arguments).

Data Types: logical

Output Arguments

collapse all

Blocks connected to buses that treat buses as vectors, returned as an array of structures. Each structure in the array contains these fields:

  • BlockPath — Character vector specifying the path to the block to which the bus connects.

  • InputPort — Integer specifying the input port to which the bus connects.

  • LibPath — If the block is a library block instance, and includeLibs is true, the field value is the path to the source library block. Otherwise, LibPath is empty ([]).

Bus to Vector blocks added by the function, specified as a cell array. If reportOnly is set to false, the cell array contains the paths to each Bus to Vector block that the function added to replace buses used as vectors. Otherwise, busToVectorBlocks is empty ([]).

Cases where function cannot insert Bus to Vector block, specified as an array of structures. Each structure in the array contains these fields:

  • BlockPath — Character vector specifying the path to the block to which the bus connects.

  • InputPort — Integer specifying the input port to which the bus connects.

These cases occur when a Bus to Vector cannot be inserted because the input virtual bus signal consists of elements with mixed attributes.

Tips

  • Before you execute this function:

    1. Ensure that the model compiles without error.

    2. Save the model.

  • Back up the model and any libraries before calling the function with reportOnly set to false.

  • To preview the effects of the change on blocks in all models, call Simulink.BlockDiagram.addBusToVector with includeLibs set to true and reportOnly set to true. Then, examine the information returned in the destBlocks output argument.

Introduced in R2007a

Was this topic helpful?