Contents

For Each

Enable blocks inside For Each Subsystem to 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 elements of the mask parameters or 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.

Iterations in the For Each Subsystem

You can use a For Each subsystems to iteratively compute output after changing inputs or mask parameters. This is done by configuring the partitioning them 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 and Partition Width parameters. For more information, see Select Partition Parameters.

Partition Parameters in the For Each block

You can partition the mask parameters of For Each subsystems. 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 subsystems, see Mask a Block. 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 specify how to decompose it into elements or subarrays for each iteration. Do this by setting integer values for the Partition Dimension and the Partition Width parameters.

As an illustration, consider a mask parameter 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.

Mask parameter 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:

    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).

Parameters and Dialog Box

Input Partition Tab

Use this tab to select each input signal you need to partition and to specify the corresponding Partition Dimension and Partition Width parameters. See the Inport block reference page for more information.

Port

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

Partition

Select the check box beside each input signal that you want to partition into subarrays or elements. Selecting this check box enables Partition Dimension and Partition Width for that input signal.

Default: Off

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.

Default: 1

Minimum: 1

Partition Width

Specify the width of each partition slice of the input signal. The default width of 1 represents a width of one element.

Default: 1

Minimum: 1

Output Concatenation Tab

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

Port

The Port column displays the output index and the name of the output port connected to the For Each Subsystem block. You can have any number of ports.

Concatenation Dimension

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

Default: 1

Minimum: 1

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.

Parameter Partition Tab

Use this tab to 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.

Parameter

The Parameter column displays the name of the mask parameter of the For Each Subsystem block.

Partition

Select the check box next to each mask parameter that you want to partition into subarrays or elements. Selecting this check box makes the Partition Dimension and Partition Width parameters available for that mask parameter.

Default: Off

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.

Default: 1

Minimum: 1

Partition Width

Specify the width of each partition slice of the input signal. The default width of 1 represents a width of one element.

Default: 1

Minimum: 1

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?