Products & Services Solutions Academia Support User Community Company

Learn more about Simulink   

Merge - Combine multiple signals into single signal

Library

Signal Routing

Description

The Merge block combines its inputs into a single output line whose value at any time is equal to the most recently computed output of its driving blocks. You can specify any number of inputs by setting the block's Number of inputs parameter.

Use Merge blocks only 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.

Merge blocks assume that all driving signals share the same signal memory. The shared signal memory should be accessed only in mutually exclusive fashion. Therefore, always use alternately executing subsystems to drive Merge blocks. See Creating Alternately Executing Subsystems for an example.

All signals that connect to a Merge block, or exist anywhere in a network of Merge blocks, are functionally the same signal, and are therefore subject to the restriction that a given signal can have at most one associated signal object. See Simulink.Signal and Multiple Signal Objects for more information.

Guidelines for Using the Merge Block

When you use the Merge block, follow these guidelines:

Proper Merge Block Usage

For each input of a Merge block, the topmost non-atomic and non-virtual source must be a conditionally-executed subsystem that is not an Iterator subsystem.

The following example shows proper Merge block usage, merging signals from two conditionally-executed subsystems.

The following figure shows another valid example of Merge block usage, with the topmost non-atomic, non-virtual source being a conditionally executed subsystem.

You can also use multiple merge blocks, as shown in the following example.

The following example is not allowed, because one input of the Merge block is connected to a Sine Wave block (not a conditionally-executed subsystem).

The following example is also not allowed, because one input of the Merge block is connected to an Iterator subsystem.

You can use the Model Advisor to check for proper Merge block usage in your model. For more information, see Check for proper Merge block usage.

Initial Output Value

You can specify an initial output value for the Merge block by setting the Initial output parameter. If you do not specify an initial output value and one or more of the driving blocks do, the Merge block's initial output equals the most recently evaluated initial output of the driving blocks.

For more information on simplified initialization mode, see Underspecified initialization detection.

Single-Input Merge

Single-input merge is not supported. Each Merge block must have at least two inputs.

Use Merge blocks only for signals that require merging. If you were previously connecting a Merge block input to a Mux block, use a multi-input Merge block instead.

Input Dimensions and Merge Offsets

The Merge block accepts only inputs of equal dimensions and outputs a signal of the same dimensions as the inputs, unless you select the Allow unequal port widths parameter.

If you select Allow unequal port widths, the block accepts scalars and vectors (but not matrices) having differing numbers of elements. Further, 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. For example, the Merge block in the following diagram has a Merge block width of

max(2+0,2+1)=3

In this example, the offset of v1 is 0 and the offset of v2 is 1. The Merge block maps the elements of v1 to the first two elements of v3 and the elements of v2 to the last two elements of v3. Only the second element of v3 is effectively merged, as seen from the scopes output.

If you use Simplified Initialization Mode, you must clear the Allow unequal port widths check box. The input port offsets for all input signals must be zero.

Consider using Merge blocks only for signal elements that require true merging. Other elements can be combined with merged elements using the Concatenate block, as shown in the following example.

For more information on simplified initialization mode, see Underspecified initialization detection.

Combining or Reordering of Input Signals

A Merge block does not accept input signals whose elements have been reordered or partially selected. In addition, you should not connect input signals to the Merge block that have been combined outside of a conditionally-executed subsystem.

For example, in the following diagram, the Merge block does not accept the output of the first Selector block because the Selector block interchanges the first and last elements of the vector signal. The Merge block does not accept the output of the second Selector block because the Selector block selects only the first three elements.

If you use simplified initialization mode, the following example is not allowed, because two signals are being combined outside of a conditionally-executed subsystem.

You can, however, combine or reorder Merge block input signals within a conditionally-executed subsystem. For example, the following diagram is valid.

For more information on simplified initialization mode, see Underspecified initialization detection.

Conditionally-Executed Subsystem Outport Reset

The Outports of conditionally-executed subsystems being merged should not reset when disabled. This action can cause multiple subsystems to update the Merge block at the same time. Specifically, the disabled subsystem updates the Merge block by resetting its output, while the enabled subsystem updates the Merge 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.

Instead of resetting the subsystem output when it is disabled, add an additional subsystem for the default case, and use control logic to run this subsystem if nothing else runs. For example, see the following:

For more information on simplified initialization mode, see Underspecified initialization detection.

Merging S-Function Outputs

The Merge block can merge a signal from an S-Function block only if the memory used to store the S-Function block's output is reusable. Simulink software 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 for more information.

Data Type Support

The Merge block accepts real or complex signals of any data type supported by Simulink software, including fixed-point and enumerated data types. All inputs must be of the same data type and numeric type.

For a discussion on the data types supported by Simulink software, see Data Types Supported by Simulink in the Simulink documentation.

Parameters and Dialog Box

Number of inputs

The number of input ports to merge.

Initial output

Initial value of output. If unspecified, the initial output equals the initial output, if any, of one of the driving blocks. Simulink software does not allow you to set the initial output of this block to inf or NaN.

Allow unequal port widths

Allows the block to accept inputs having different numbers of elements.

Input port offsets

Vector specifying the offset of each input signal relative to the beginning of the output signal.

Bus Support

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

All signals in a nonvirtual bus input to a Merge block must have the same sample time, even if the elements of the associated bus object specify inherited sample times. You can use a Rate Transition block to change the sample time of an individual signal, or of all signals in a bus. See Using Composite Signals and Bus-Capable Blocks for more information.

Characteristics

Bus-capable

Yes, with restrictions as noted above

Direct Feedthrough

Yes

Sample Time

Inherited from the driving block

Scalar Expansion

No

Dimensionalized

Yes

Multidimensionalized

Yes

Zero Crossing

No

  


Related Products & Applications

Learn more about Simulink through this collection of videos, articles, technical literature and the Getting Started with Simulink Guide.

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