Main Content

Assign Signal Values to Bus Elements

To replace the value of a bus element, use a Bus Assignment block. You do not need to use Bus Selector and Bus Creator blocks to change the value of a bus element.

Open and compile the example model named BusAssignment. To compile the model, on the Modeling tab of the Simulink Toolstrip, click Update Model or Run. Compiling the model updates the line styles, which you can use to visually identify buses.

The Bus Assignment block has two input ports. The first input port receives the bus that contains an element to which you want to assign a new value. The bus can be virtual or nonvirtual. The second input port receives the signal whose value you want to assign to the bus element.

Double-click the Bus Assignment block to open a dialog box with assignment options. The Block Parameters dialog box lists the elements available for assignment in the Elements in the bus list.

In this model, bus elements a and b are available for assignment.

Element a also appears in the Elements that are being assigned list, which indicates that the element is selected for assignment.

The port label on the block indicates the corresponding element. For element a, the port label is :=a.

To assign a new value to the bus element, connect the signal that provides the new value to the corresponding port on the Bus Assignment block. The elements to which you assign values can be buses or nonbus signals. The new values must match the attributes of the elements in the original bus.

In this model, signal c connects to the port that assigns a new value to element a. The Bus Assignment block replaces the value of bus element a, which is 1, with the value of signal c, which is 3.

To display the new value of element a and the unchanged value of element b, the Bus Selector block selects elements a and b and connects them to Display blocks. The Display blocks show the value of these elements after assignment.

  • Element a has a value of 3, which is its new value from the Bus Assignment block.

  • Element b has a value of 2, which is its original value.

You can select additional elements for assignment by selecting an element under Elements in the bus then clicking Select. The Bus Assignment block adds an input port for each additional element to which you want to assign a new value. The new input ports let you connect the signals that you want to assign to the additional bus elements.

See Also

Blocks

Related Topics