For Each

Process elements or subarrays of a mask parameter or 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 the elements of input signals or mask parameters independently. Each block inside this subsystem that has states maintains a separate set of states for each element or subarray that it processes. As the set of blocks in the subsystem processes the elements or subarrays, the subsystem concatenates the results to form output signals.

You can use a For Each subsystem to iteratively compute output after changing inputs or mask parameters. To do so, you configure the partitioning of input signals or mask parameters in the For Each block dialog box.

Partition Input Signals to the Subsystem

In a For Each subsystem, you can specify which input signals to partition for each iteration using the Input Partition tab in the dialog box of the For Each block. When specifying a signal to be partitioned, you also have to specify the Partition Dimension, Partition Width, and Partition Offset parameters.

Partition Parameters in the For Each block

You can partition the mask parameters of a For Each Subsystem block. Partitioning is useful for systems that have identical structures in each iteration but different parameter values. In this case, changing the model to partition extra input signals for each parameter is cumbersome. Instead, add a mask parameter to a For Each subsystem. For more information, see Create a Simple Mask. To select the mask parameter for partitioning, use the Parameter Partition tab on the For Each block dialog box. For more information, see Select Partition Parameters

Concatenate Output

You define the dimension along which to concatenate the results by specifying the Concatenation Dimension in the Output Concatenation tab.

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.

Select Partition Parameters

When selecting an input signal or subsystem mask parameter for partitioning, you need to specify how to decompose it into elements or subarrays for each iteration. Do this by setting integer values for the Partition Dimension, Partition Width, and Partition Offset parameters.

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

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

Matrix A decomposes into these 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 addition to setting the Partition Dimension to 2, if you set the Partition Width to 2 and the Partition Offset to -1, Simulink uses two overlapping 3x2 partitions for processing.

For an example using the Partition Offset parameter, open the Simulink model slexForEachOverlapExample.

Note

Only signals are considered one-dimensional in Simulink. Mask parameters are row or column vectors, according to their orientation. To partition a row vector, specify the partition dimension as 2 (along the columns). To partition a column vector, specify the partition dimension as 1 (along the rows).

Ports

Input

expand all

Placing an Inport block in a subsystem block adds an external input port to the block. The port label matches the name of the Inport block.

Use Inport blocks to get signals from the local environment.

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

Output

expand all

Placing an Outport block in a subsystem block adds an output port from the block. The port label on the subsystem block is the name of the Outport block.

Use Outport blocks to send signals to the local environment.

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

Parameters

expand all

Input Partition Tab

Select each input signal you want to partition and to specify the corresponding Partition Dimension and Partition Width parameters. See the Inport block reference page for more information.

List of input ports connected to the For Each Subsystem block.

Select input ports signals connected to the For Each Subsystem block to partition into subarrays or elements.

off

Clear input port signals.

on

Select input port signals to partition.

Dependency

Selecting this parameter enables the Partition Dimension and Partition Width parameters for the selected input port signal.

Programmatic Use

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

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.

1

Specify a dimension of 1.

integer

Specify dimension. Minimum value 1.

Programmatic Use

Block Parameter: InputPartitionDimension
Type: character vector
Values: '1' | '<integer>'
Default: '1'

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

1

Width of one element.

integer

Specify width. Minimum value 1.

Programmatic Use

Block Parameter: InputPartitionWidth
Type: character vector
Values: '1' | '<integer>'
Default: '1'

Specify the offset for each partition slice of the input signal.

0

No offset between partition slices.

integer

Specify partition offset where the sum of the partition width and the partition offset is a positive integer.

For example, a Partition Width of 3 and a Partition Offset of -2 indicates that each 3 element slice overlaps its neighboring slices by 2 elements.

Programmatic Use

Block Parameter: SubsysMaskParameterOffset
Type: character vector
Values: '0' | '<integer>'
Default: '0'

Control display of output port for partition index.

off

Hide output port.

on

Display output port on block.

Dependency

Selecting this parameter enables the Partition index output data type parameter.

Programmatic Use

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

Specify partition index data type for output port

int32

Select signed 32-bit integer.

double

Select double real.

Programmatic Use

Block Parameter: IterationIndexDataType
Type: character vector
Values: 'int32' | 'double'
Default: 'int32'

Output Concatenation Tab

For each output port, specify the dimension along which to stack (concatenate) the For Each Subsystem block results. See the Outport block reference page for more information.

List of output ports connected to the For Each Subsystem block.

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

1

The results stack in the d1 direction. If the block generates column vectors, the concatenation process results in a single column vector.

integer

The results stack in the d2 direction. If the block generates row vectors, the concatenation process results in a single row vector. Minimum value 1

Programmatic Use

Block Parameter: OutputConcatenationDimension
Type: character vector
Values: '1' | '<integer>'
Default: '1'

Parameter Partition Tab

Select each mask parameter to partition and to specify the corresponding Partition Dimension and Partition Width parameters. Parameters appear in the list only if you have added an editable parameter to the mask of the parent For Each subsystem.

List of mask parameters for the For Each Subsystem block.

Select mask parameters for the For Each Subsystem block to partition into subarrays or elements.

off

Clear mask parameters.

on

Select mask parameters to partition.

Dependency

Selecting this parameter enables the Partition Dimension and Partition Width parameters for the selected mask parameter.

Programmatic Use

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

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

Programmatic Use

Block Parameter: SubsysMaskParameterPartitionDimension
Type: character vector
Values: '1' | '<integer>'
Default: '1'

Specify the width of each partition slice of the input signal as an integer greater than or equal to one.

Programmatic Use

Block Parameter: SubsysMaskParameterPartitionWidth
Type: character vector
Values: '1' | '<integer>'
Default: '1'

Introduced in R2010a