Assign Signal Values to Bus Elements
This example shows how to use a Bus Assignment block to replace the value of a bus element. You do not need to add Bus Selector and Bus Creator blocks to change the value of a bus element.
Open and simulate the example model.
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
b are available for assignment. Element
a also appears in the Elements that are being assigned list, which indicates that it is selected for assignment.
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 nonbus signals or buses. 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 port label indicates the bus element. For element
a, the port label is :=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
b and connects them to Display blocks. The Display blocks show the value of these elements after assignment.
ahas a value of 3, which is the new, assigned value from the Bus Assignment block.
bhas 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.