Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Contents

Simulink.BlockDiagram.addBusToVector

Add Bus to Vector blocks to convert virtual bus signals into vector signals

Syntax

[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector('model')
[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector('model', includeLibs)
[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector('model', includeLibs, reportOnly)

Description

[DstBlocks, BusToVectorBlocks] = 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. Before executing this function, you must do the following:

  1. Set Simulation > Model Configuration Parameters > Diagnostics > Connectivity > Buses > Mux blocks used to create bus signals to error, or equivalently, execute set_param (model, 'StrictBusMsg', 'ErrorLevel1').

  2. Ensure that the model compiles without error.

  3. Save the model.

[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector('model', includeLibs) is equivalent to [DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector(model) if includeLibs is false.

If includeLibs is true, the function searches library blocks rather than excluding them.

[DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector('model', includeLibs, reportOnly) is equivalent to [DstBlocks, BusToVectorBlocks] = Simulink.BlockDiagram.addBusToVector(model, includeLibs) if reportOnly is true.

If reportOnly is false, the function inserts a Bus to Vector block into each bus that is used as a vector in any block that it searches. The search excludes or includes library blocks as specified by includeLibs. The insertion replaces the implicit use of a bus as a vector with an explicit conversion of the bus to a vector. The signal's source and destination blocks are unchanged by this insertion.

If Simulink.BlockDiagram.addBusToVector adds Bus to Vector blocks to the model or any library, the function permanently changes the saved copy of the diagram. Be sure to back up the model and any libraries before calling the function with reportOnly specified as false.

If Simulink.BlockDiagram.addBusToVector changes a library block, the change affects every instance of that block in every Simulink® model that uses the library. To preview the effects of the change on blocks in all models, call Simulink.BlockDiagram.addBusToVector with includeLibs = true and reportOnly = true, then examine the information returned in DstBlocks.

Input Arguments

model

Model name or handle

includeLibs

Boolean specifying whether to search library blocks (true) or only the top-level model (false).

Default: false

reportOnly

Boolean specifying whether to change the model (false) or just generate a report (true).

Default: true

Output Arguments

DstBlocks

An array of structures that contain information about blocks that are connected to buses but treat the buses as vectors. If no such blocks exist the array has 0 length. Each structure in the array contains the following fields:

BlockPath

String specifying the path to the block to which the bus connects

InputPortInteger specifying the input port to which the bus connects
LibPathIf the block is a library block instance, and includeLibs is true, the path to the source library block. Otherwise, LibPath is empty ([]).

BusToVectorBlocks

If reportOnly is false, and model contains any buses used as vectors, a cell array containing the path to each Bus to Vector block that was added to the model. Otherwise, BusToVectorBlocks is empty ([]).

Tip

You can eliminate warnings and errors about virtual buses used as muxes by using Simulink.BlockDiagram.addBustoVector to insert a Bus to Vector block into any virtual bus signal that is used as a mux. For additional information, see Prevent Bus and Mux Mixtures.

Examples

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

If the model shown is open as the current model, you can eliminate the implicit conversion with the following command:

Simulink.BlockDiagram.addBusToVector(gcs, false, false)

Rebuilding and simulating the model then gives this result:

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

See Also

| | | | | | | | |

Was this topic helpful?