Quantcast

Documentation Center

  • Trial Software
  • Product Updates

Mux

Combine several input signals into vector

Library

Signal Routing

Description

The Mux block combines its inputs into a single vector output. An input can be a scalar or vector signal. All inputs must be of the same data type and numeric type. The elements of the vector output signal take their order from the top to bottom, or left to right, input port signals. See How to Rotate a Block for a description of the port order for various block orientations. To avoid adding clutter to a model, Simulink® hides the name of a Mux block when you copy it from the Simulink library to a model. See Mux Signals for information about creating and decomposing vectors.

    Note:   The Mux block allows you to connect signals of differing data and numeric types and matrix signals to its inputs. In this case, the Mux block acts like a Bus Creator block and outputs a bus signal rather than a vector. MathWorks discourages using Mux blocks to create bus signals, and might not support this practice in future releases. See Prevent Bus and Mux Mixtures for more information.

Use the Number of inputs parameter to specify input signal names and sizes as well as the number of inputs. You can use one of the following formats:

FormatBlock Behavior

Scalar

Specifies the number of inputs to the Mux block.

When you use this format, the block accepts scalar or vector signals of any size. Simulink assigns each input the name signalN, where N is the input port number.

Vector

The length of the vector specifies the number of inputs. Each element specifies the size of the corresponding input.

A positive value specifies that the corresponding port can accept only vectors of that size. For example, [2 3] specifies two input ports of sizes 2 and 3, respectively. If an input signal width does not match the expected width, an error message appears. A value of -1 specifies that the corresponding port can accept scalars or vectors of any size.

Cell array

The length of the cell array specifies the number of inputs. The value of each cell specifies the size of the corresponding input.

A scalar value N specifies a vector of size N. A value of -1 means that the corresponding port can accept scalar or vector signals of any size.

Signal name list

You can enter a list of signal names separated by commas. Simulink assigns each name to the corresponding port and signal. For example, if you enter position,velocity, the Mux block will have two inputs, named position and velocity.

Simulink provides several techniques for combining signals into a composite signal. For a comparison of techniques, see Techniques for Combining Signals. MathWorks encourages using Vector Concatenate blocks rather than Mux blocks to combine vectors. The primary exception is the creation of a vector of function calls, which requires a Mux block. In future releases, Mux blocks might have no unique capabilities and might be deprecated.

    Tip  

To create a composite signal, in which the constituent signals retain their identities and can have different data types, use a Bus Creator block rather than a Mux block. Although you can use a Mux block to create a composite signal, MathWorks discourages this practice. See Prevent Bus and Mux Mixtures for more information.

Data Type Support

The Mux block accepts real or complex signals of any data type that Simulink supports, including fixed-point and enumerated data types.

For more information, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

Number of inputs

Specify number and size of inputs.

Settings

Default: 2

You can enter a comma-separated list of signal names for this parameter field.

Command-Line Information

See Block-Specific Parameters for the command-line information.

Display option

Specify the appearance of the block in the model.

Settings

Default: bar

bar

Displays the block in a solid foreground color

none

Mux appears inside the block

signals

Displays signal names next to each port

Command-Line Information

See Block-Specific Parameters for the command-line information.

Examples

The sf_carsf_car model uses a Mux block to combine two signals for input to a Scope block:

The sf_aircontrolsf_aircontrol model uses a Mux block to combine two signals for input to a Stateflow® chart:

The following models also show how to use the Mux block:

  • sldemo_auto_climatecontrol

  • sldemo_suspn

  • sldemo_zeroxing

  • penddemo

Characteristics

Virtual

Yes

For more information, see Virtual Blocks in the Simulink documentation.

See Also

Demux

Was this topic helpful?