Assign 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, in the Simulink® Toolstrip, on the Modeling tab, click Update Model. 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 a bus named
constants
.The second input port receives a signal named
c
.
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, 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.
To indicate the element that corresponds with an assignment port, the port label on the block icon includes the element name. For element a
, the port label is :=a.
Signal c
connects to the assignment port for element a
. The Bus Assignment block replaces the value of 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 these elements connect to Display blocks.
To populate the Display blocks, in the Simulink Toolstrip, on the Modeling tab, click Run.
The Display blocks show the value of the 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 elements.