Main Content

Replace Values of Bus Elements

To assign the value of an input to a bus element, you can use a Bus Assignment block. Use a Bus Assignment block to change bus element values without adding Bus Selector and Bus Creator blocks that select bus elements and reassemble them into a bus.

Connect to the Bus Assignment block ports:

  • The bus to which you want to assign the values

  • The lines whose values you want to assign to specified bus elements

Connect the bus to the first input port of the Bus Assignment block, and one or more lines with values to be assigned to the other ports. The Block Parameters dialog box lists the elements available for assignment in the bus. The bus can be virtual or nonvirtual. Select the elements to which you want to assign values. If you specify more than one element to assign values to, the Bus Assignment block adds ports.

The elements that you assign values to can be nonbus or bus signals. The new values must match the attributes of the elements in the original bus.

Update a Bus Element

This simple example illustrates the mechanics of using the Bus Assignment block. In more complex models, using a Bus Assignment block simplifies updating a bus to reflect the processing that occurs in a separate component, such as a subsystem or referenced model. Here is the model after you simulate it.

Some key steps in constructing this model are:

  1. Connect two Constant blocks to a Bus Creator block. The value of signal a is 1, and the value of signal b is 2.

  2. Connect the Bus Creator output bus const_bus to the first port of a Bus Assignment block. The bus elements a and b are available to assign new values to them.

  3. Connect the Constant block output signal c to the second port of the Bus Assignment block.

  4. For the Bus Assignment block, in the Block Parameters dialog box Elements in the bus list, select the a signal and click Select.

  5. Use a Bus Selector to select signals a and b from the const_bus bus and connect those signals to Display blocks.

  6. Simulate the model. The Display blocks show that the value of signal a, which was 1 when the const_bus bus was created, is now 3, reflecting the assignment of the c signal from the Const3 block.

See Also


Related Topics