Documentation Center

  • Trial Software
  • Product Updates

Demux

Extract and output elements of vector signal

Library

Signal Routing

Description

The Demux block extracts the components of an input signal and outputs the components as separate signals. The output signals are ordered from top to bottom output port. 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 Demux block when you copy it from the Simulink library to a model. See Mux Signals for information about creating and decomposing vectors.

The Number of outputs parameter allows you to specify the number and, optionally, the dimensionality of each output port. If you do not specify the dimensionality of the outputs, the block determines the dimensionality of the outputs for you.

The Demux block operates in either vector mode or bus selection mode, depending on whether you selected the Bus selection mode parameter. The two modes differ in the types of signals they accept. Vector mode accepts only a vector-like signal, that is, either a scalar (one-element array), vector (1-D array), or a column or row vector (one row or one column 2-D array). Bus selection mode accepts only a bus signal.

    Note:   MathWorks discourages enabling Bus selection mode and using a Demux block to extract elements of a bus signal. Muxes and buses should not be intermixed in new models. See Prevent Bus and Mux Mixtures for more information.

The Number of outputs parameter determines the number and dimensionality of the block outputs, depending on the mode in which the block operates.

Specifying the Number of Outputs in Vector Mode

In vector mode, the value of the parameter can be a scalar specifying the number of outputs or a vector whose elements specify the widths of the block's output ports. The block determines the size of its outputs from the size of the input signal and the value of the Number of outputs parameter.

The following table summarizes how the block determines the outputs for an input vector of width n.

Parameter ValueBlock outputs...Comments

p = n

p scalar signals

For example, if the input is a three-element vector and you specify three outputs, the block outputs three scalar signals.

p > n

Error

 

p < n

n mod p = 0

p vector signals each having n/p elements

If the input is a six-element vector and you specify three outputs, the block outputs three two-element vectors.

p < n

n mod p = m

m vector signals each having (n/p)+1 elements and p-m signals having n/p elements

If the input is a five-element vector and you specify three outputs, the block outputs two two-element vector signals and one scalar signal.

[p1 p2 ... pm]

p1+p2+...+pm=n

pi > 0

m vector signals having widths p1, p2, ... pm

If the input is a five-element vector and you specify [3, 2] as the output, the block outputs three of the input elements on one port and the other two elements on the other port.

[p1 p2 ... pm]

p1+p2+...+pm=n

some or all

pi = -1

m vector signals

If pi is greater than zero, the corresponding output has width pi. If pi is -1, the width of the corresponding output is dynamically sized.

[p1 p2 ... pm]

p1+p2+...+pm!=n

pi = > 0

Error

 

Note that you can specify the number of outputs as fewer than the number of input elements, in which case the block distributes the elements as evenly as possible over the outputs as illustrated in the following exampleexample:

You can use –1 in a vector expression to indicate that the block should dynamically size the corresponding port. For example, the expression [-1, 3 -1] causes the block to output three signals where the second signal always has three elements. The sizes of the first and third signals depend on the size of the input signal.

If a vector expression comprises positive values and –1 values, the block assigns as many elements as needed to the ports with positive values and distributes the remain elements as evenly as possible over the ports with –1 values. For example, suppose that the block input is seven elements wide and you specify the output as [-1, 3 -1]. In this casethis case, the block outputs two elements on the first port, three elements on the second, and two elements on the third.

Specifying the Number of Outputs in Bus Selection Mode

In bus selection mode, the value of the Number of outputs parameter can be a:

  • Scalar specifying the number of output ports

    The specified value must equal the number of input signals. For exampleexample, if the input bus comprises two signals and the value of this parameter is a scalar, the value must equal 2.

  • Vector each of whose elements specifies the number of signals to output on the corresponding port

    For example, if the input bus contains five signals, you can specify the output as [3, 2], in which case the block outputs three of the input signals on one port and the other two signals on a second port.

  • Cell array each of whose elements is a cell array of vectors specifying the dimensions of the signals output by the corresponding port

The cell array format constrains the Demux block to accept only signals of specified dimensions. For example, the cell array {{[2 2], 3} {1}} tells the block to accept only a bus signal comprising a 2-by-2 matrix, a three-element vector, and a scalar signal. You can use the value –1 in a cell array expression to let the block determine the dimensionality of a particular output based on the input. For example, the following diagramdiagram uses the cell array expression {{–1}, {–1,–1}} to specify the output of the leftmost Demux block.

In bus selection mode, if you specify the dimensionality of an output port (that is, specify any value other than –1), the corresponding input element must match the specified dimensionality.

    Note:   MathWorks discourages enabling Bus selection mode and using a Demux block to extract elements of a bus signal. Muxes and buses should not be intermixed in new models. See Prevent Bus and Mux Mixtures for more information.

Data Type Support

The Demux block accepts and outputs complex or real 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 outputs

Specify the number and dimensions of outputs.

Settings

Default: 2

This block interprets this parameter depending on the Bus selection mode parameter. See the block description for more information.

Command-Line Information

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

See Also

See the Demux block reference page for more information.

Display option

Select options to display the Demux block. The options are

Settings

Default: bar

bar

Display the icon as a solid bar of the block's foreground color.

none

Display the icon as a box containing the block's type name.

Command-Line Information

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

See Also

See the Demux block reference page for more information.

Bus selection mode

Enable bus selection mode.

Settings

Default: Off

On

Enable bus selection mode.

Off

Disable bus selection mode.

Tips

MathWorks discourages enabling Bus selection mode and using a Demux block to extract elements of a bus signal. Muxes and buses should not be intermixed in new models. See Prevent Bus and Mux Mixtures for more information.

Command-Line Information

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

Characteristics

Virtual

Yes

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

See Also

Mux

Was this topic helpful?