Using Muxes

A mux is an indexed vector that implements a composite signal. In the Simulink® software documentation, indexed vectors are also called "vectors" and "wide signals", and both "mux" and "vector" appear in GUI labels and API names. The underlying software construct, an indexed vector, is always the same; the difference is the context in which the construct appears.

Mux signals are virtual signals, and the blocks that manipulate muxes are virtual blocks. All signals in a mux must have the same attributes. The Signal Routing library provides two blocks that you can use for implementing muxes:

Mux

Combine several input signals into a mux signal

Demux

Extract and output the elements of a mux signal

To create a mux signal:

  1. Clone a Mux and Demux block from the Signal Routing library.

  2. Set the Mux blocks Number of inputs and the Demux block's Number of outputs properties to the desired values.

  3. Connect the Mux, Demux, and other blocks as needed to implement the desired composite signal.

The next figure shows three signals that are input to a Mux block, transmitted as a mux signal to a Demux block, and output as separate signals.

The Mux and Demux blocks are the left and right vertical bars, respectively. Consistent with the goal of reducing visual complexity, neither block displays a name. The line connecting the blocks, representing the mux signal, is wide because the model has been built with Format > Port/Signal Displays > Wide Nonscalar Lines enabled in the model menu. See Displaying Signal Properties for details.

Because the Mux and Demux blocks are virtual blocks, and a mux signal is a virtual signal, they have no effect on simulation or code generation. Thus the simulation results and generated code for the above model would be exactly the same if the Mux blocks were eliminated and the mux signal replaced by three nonvirtual signals:

Signals input to a Mux block can be virtual composite signals, but the resulting mux is flat, not hierarchical. The signals in the mux appear in the order in which they were input to the Mux block. Use a bus rather than a mux if you want to nest composite signals. See Using Buses for details.

Signals input to a Mux block should all have the same attributes. If they do not, the block will output a bus rather than a mux, unless you have configured the model to disable this practice. The MathWorks discourages using Mux blocks to create buses. See Intermixing Composite Signal Types for details.

If a Demux block has more outputs than the number of signals in the input mux, an error occurs. A Demux block can have fewer outputs than the number of signals in the input mux. See the Demux block documentation for details.

A Demux block can input a bus unless you have configured the model to disable this practice. The MathWorks discourages using Demux blocks to access buses. See Intermixing Composite Signal Types for details.

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS