Main Content

Merge

Combine multiple signals into single signal

  • Library:
  • Simulink / Signal Routing

  • Merge block

Description

The Merge block combines inputs into a single output. The output value at any time is equal to the most recently computed output of its driving blocks. Specify the number of inputs by setting the Number of inputs parameter.

Use a Merge block to interleave input signals that update at different times into a combined signal in which the interleaved values retain their separate identities and times. To combine signals that update at the same time into an array or matrix signal, use a Concatenate block.

Guidelines for Using the Merge Block

When you use the Merge block, follow these guidelines:

  • Always use conditionally executed subsystems to drive Merge blocks, without any intervening blocks.

  • Ensure that at most one of the driving conditionally executed subsystems executes at any time step.

  • Ensure that all input signals have the same sample time.

  • Do not branch a signal that inputs to a Merge block.

  • For all conditionally executed subsystem Outport blocks that drive Merge blocks, set Output when disabled to held.

  • If the output of a Model block is coming from a MATLAB Function block or a Stateflow® chart, do not connect that output port to the input port of the Merge block.

  • The Merge block supports merging signals in different tasks to a root Outport block.

For each input of a Merge block, the topmost nonvirtual source must be a conditionally executed subsystem (not including a For Iterator or While Iterator subsystem).

The next diagram shows valid Merge block usage, merging signals from two conditionally executed subsystems.

Bus Support

The Merge block is a bus-capable block. The inputs can be virtual or nonvirtual bus signals subject to these restrictions:

  • The number of inputs must be greater than one.

  • Initial output must be zero, a nonzero scalar, or a finite numeric structure.

  • The Allow unequal port widths check box must be cleared.

  • All inputs must be buses and must be equivalent (same hierarchy with identical names and attributes for all elements).

All signals in a nonvirtual bus input to a Merge block must have the same sample time. You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus.

Merging S-Function Outputs

The Merge block can merge a signal from an S-Function block only if the memory used to store the output from the S-Function block is reusable. Simulink® displays an error message if you attempt to update or simulate a model that connects a nonreusable port of an S-Function block to a Merge block. See ssSetOutputPortOptimOpts.

Multi-tasked Root Outputs

A Merge block connected to a root Outport block allows merging signals in different tasks by allowing those signals to write to the root Outport block simultaneously. A Union sample time of the sources is assigned to the Merge block.

All the sources of the Merge block that are in the same task should be inside conditionally executed subsystems that should not output simultaneously in the same time step.

Limitations

  • All signals that connect to a Merge block are functionally the same signal. Therefore, they are subject to the restriction that a given signal can have at most one associated signal object. See Simulink.Signal for more information.

  • Run-time diagnostics do not run if the inputs to a Merge block are from a single initiator. For example, a single initiator could be a Stateflow chart executing function-call subsystems that are connected to a Merge block.

  • Do not set the outports of conditionally executed subsystems being merged to reset when disabled. This action can cause multiple subsystems to update the block at the same time. Specifically, the disabled subsystem updates the Merge block by resetting its output, while the enabled subsystem updates the block by computing its output.

    To prevent this behavior, set the Outport block parameter Output when disabled to held for each conditionally executed subsystem being merged.

  • A Merge block does not accept input signals whose elements have been reordered or partially selected, as shown in the next diagram.

    Simulink block diagram including 2 enabled subsystems, each of whose outputs is connected to a Selector block. The outputs of both Selector blocks are connected to a Merge block. One Selector block reorders its input signal before passing it to the Merge block, and the other Selector block selects a subset of its input signal before passing it to the Merge block.

  • Do not connect input signals to the block that have been combined outside of a conditionally executed subsystem.

You can use an array of buses as an input signal to a Merge block with these limitations:

  • Allow unequal port widths — Clear this parameter.

  • Initial condition — You can specify this parameter using:

    • The value 0. In this case, each of the individual signals in the array of buses use the initial value 0.

    • An array of structures that specifies an initial condition for each of the individual signals in the array of buses.

    • A single scalar structure that specifies an initial condition for each of the elements that the bus type defines. Use this technique to specify the same initial conditions for each of the buses in the array.

Ports

Input

expand all

First input signal merged with the other input signals.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

nth input signal merged with the other input signals.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Output

expand all

Output signal merged from the input signals.

Data Types: single | double | half | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | Boolean | fixed point | enumerated | bus

Parameters

expand all

Specify the number of input signals to merge. The block creates a port for each input signal.

Programmatic Use

Block Parameter: Inputs
Type: character vector
Values: integer
Default: '2'

Specify the initial value of the output signal. If you do not specify an initial output value, then initial output depends on the initialization mode and the driving blocks.

In Simplified Initialization Mode, for an unspecified (empty matrix []) value of Initial output, the block uses the default initial value of the output data type. For information on the default initial value, see Initialize Signal Values. In Classic Initialization Mode, for an unspecified (empty matrix []) value of Initial output, the initial output of the block equals the most recently evaluated initial output of the driving blocks. Since the initialization ordering for these sources can vary, initialization can be inconsistent for the simulation and the code generation of a model.

Programmatic Use

Block Parameter: InitialOutput
Type: character vector
Values: scalar | vector
Default: '[ ]'

Select this parameter to allow the block to accept inputs having different numbers of elements from each other or from the output. The block allows you to specify an offset for each input signal relative to the beginning of the output signal. The width of the output signal is

max(w1+o1, w2+o2, ... wn+on)

where w1, ... wn are the widths of the input signals and o1, ... on are the offsets for the input signals.

If you clear this parameter, the Merge block accepts only inputs of equal dimensions and outputs a signal of the same dimensions as the inputs.

Note

Do not select this parameter unless your model is using Classic Initialization Mode.

Programmatic Use

Block Parameter: AllowUnequalInputPortWidths
Type: character vector
Values: 'off' | 'on'
Default: 'off'

Enter a vector to specify the offset of each input signal relative to the beginning of the output signal.

Dependencies

To enable this parameter, select Allow unequal port widths.

Programmatic Use

Block Parameter: InputPortOffsets
Type: character vector
Values: scalar | vector
Default: '[ ]'

Block Characteristics

Data Types

Boolean | bus | double | enumerated | fixed point | half | integer | single | string

Direct Feedthrough

yes

Multidimensional Signals

yes

Variable-Size Signals

no

Zero-Crossing Detection

no

Extended Capabilities

Fixed-Point Conversion
Design and simulate fixed-point systems using Fixed-Point Designer™.

Introduced before R2006a