Process elements or subarrays of a mask parameter or input signal independently
Ports & Subsystems
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.
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.
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
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.
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.
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).