Documentation Center

  • Trial Software
  • Product Updates

For Each

Enable blocks inside For Each Subsystem to process elements or subarrays of input signal independently

Library

Ports & Subsystems

Description

The For Each block serves as a control block for the For Each Subsystem block. Specifically, the For Each block enables the blocks inside the For Each Subsystem to process elements or subarrays of the input signals independently. Each block inside this subsystem that has states maintains a separate set of states for each element or subarray it processes. As the set of blocks in the subsystem process the elements (or subarrays), the subsystem concatenates the results to form output signals.

Using the For Each block, you specify how to decompose each input signal to the subsystem into elements or subarrays by setting the integer values of the Partition Dimension and the Partition Width. Similarly, you define the dimension along which to concatenate the results by specifying the Concatenation Dimension.

As an illustration, consider an input signal A of the form:

The labels d1 and d2, respectively define dimension 1 and dimension 2. If you retain the default setting of 1 for both the partition dimension and the partition width, then Simulink slices perpendicular to partition dimension d1 at a width equal to the partition width, one element.

Input signal A decomposes into the following three row vectors:

If instead you specify d2 as the partition dimension by entering the value 2, Simulink slices perpendicular to d2 to form three column vectors:

In either case, the results generated by the block for each subarray stack along the concatenation dimension, d1 (y-axis). Whereas, if you specify d2 by setting the concatenation dimension to 2, the results concatenate along the d2 direction (x-axis). Thus if the process generates row vectors, then the concatenated result is a row vector.

Parameters and Dialog Box

Partition Input(s)

Use this table to select each input signal that you need to partition and to specify the corresponding Partition Dimension and Partition Width parameters.

Port

The Port column displays the input index and the name of the input port connected to the For Each Subsystem block.

Tip

You can have any number of ports.

Command-Line Information

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

Partition

Select the check box beside each input signal that you want to partition into subarrays or elements.

Settings

Default: Off

On

Enables the partitioning of the input signal.

Off

Disables the partitioning of the input signal.

Dependencies

Selecting this check box enables the Partition Dimension and Partition Width parameters.

Command-Line Information

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

Partition Dimension

Specify the dimension through which to slice the input signal array. The resulting slices are perpendicular to the dimension that you specify. The slices also partition the array into subarrays or elements, as appropriate.

Settings

Default: 1

Minimum: 1

Tip

Specify the corresponding width of each slice by setting the Partition Width parameter for a given input port.

Command-Line Information

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

Partition Width

Specify the width of each partition slice of the input signal.

Settings

Default: 1

Minimum: 1

Tips

  • The default width of 1 represents a width of one element.

  • Specify this parameter with the Partition Dimension parameter to define fully how to create the partitioned signal.

Command-Line Information

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

Concatenate Output(s)

For each output port, specify the dimension along which to stack (concatenate) the For Each Subsystem results.

Port

The Port column displays the output index and the name of the output port connected to the For Each Subsystem block.

Tip

You can have any number of ports.

Command-Line Information

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

Concatenation Dimension

Specify the dimension along which to stack the results of the For Each Subsystem.

Settings

Default: 1

Minimum: 1

Tips

  • If you specify the default, the results stack in the d1 direction. Thus if the block generates column vectors, the concatenation process results in a single column vector.

  • If you specify 2, the results stack in the d2 direction. Thus if the block generates row vectors, the concatenation process results in a single row vector.

Command-Line Information

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

Examples

The following model demonstrates the partitioning of an input signal by a For Each block. Each row of this 2-by-3 input array contains three integers that represent the (x, y, z)-coordinates of a point. The goal is to translate each of these points based on a new origin at (–20, –10, –5) and to display the results.

By placing the process of summing an input signal and the new origin inside of a For Each Subsystem, you can operate on each set of coordinates by partitioning the input signal into two row vectors. To accomplish such partitioning, use the default settings of 1 for both the partition dimension and the partition width. If you also use the default concatenation dimension of 1, each new set of coordinates stacks in the d1 direction, making your display a 2-by-3 array.

Alternatively, if you specify a concatenation dimension of 2, then you get a single row vector because each set of results stacks in the d2 direction.

This example shows how to partition an input signal. To learn how the For Each block and subsystem handle a model with states, see the For Each Subsystem documentation.

Was this topic helpful?