Main Content

Simulink.Bus.addElementToPort

Add element to input bus element port

Since R2022b

Description

example

Simulink.Bus.addElementToPort(sys,bep,elem) adds an element, elem, to the bus element port specified by bep of the model or subsystem specified by sys. This function does not add a block to the model or subsystem.

Examples

collapse all

Suppose you want to create a model that receives bus input or provides bus output. The bus contains a bus named sinusoidal, a signal named constant, and a bus named nonsinusoidal. The sinusoidal bus contains signals named sine and chirp. The nonsinusoidal bus contains signals named pulse and saw.

Open a new model named BusInterfaces.

mdl = "BusInterfaces";
new_system(mdl);
open_system(mdl);

Add an In Bus Element or Out Bus Element block to the model. Name the port Sources. Specify sine as the element selected by the block. When you specify sine, use dots to indicate the levels of bus hierarchy.

add_block("simulink/Ports & Subsystems/In Bus Element", ...
    "BusInterfaces/InBusElement", ...
    PortName="Sources", ...
    Element="sinusoidal.sine");

When you do not specify an element for the block to select, by default, the block selects an element named signal1.

Add the remaining elements to the port that corresponds with the block.

Simulink.Bus.addElementToPort(mdl,"Sources","sinusoidal.chirp");
Simulink.Bus.addElementToPort(mdl,"Sources","constant");
Simulink.Bus.addElementToPort(mdl,"Sources","nonsinusoidal.pulse");
Simulink.Bus.addElementToPort(mdl,"Sources","nonsinusoidal.saw");

Input Arguments

collapse all

Model name or subsystem block path, specified as a character vector or string scalar.

Data Types: char | string

Bus element port name, specified as a character vector or string scalar.

Data Types: char | string

New bus element, specified as a character vector or string scalar.

For elements of nested buses, use dots to indicate each level of bus hierarchy. For example, to add a nested bus named sinusoidal with an element named sine, set element to sinusoidal.sine.

Tips

To add an element to a bus when a Simulink.Bus object specifies the bus hierarchy, edit the Simulink.Bus object.

Data Types: char | string

Alternative Functionality

  • In the In Bus Element block dialog box or Property Inspector, click the Add element button arrow. Then, select Add element without block.

  • In the Out Bus Element block dialog box or Property Inspector, click Add element. Then, select Add element without block.

Version History

Introduced in R2022b

expand all