Repeat execution of a subsystem during a time step for a specified number of iterations
Ports & Subsystems
The For Iterator block, when placed in a Subsystem
block, repeats the execution of a subsystem during the current time step until an
iteration variable exceeds the specified iteration limit. You can use this block to
implement the block diagram equivalent of a for
loop in a programming
language.
The output of a For Iterator Subsystem block cannot be a function-call signal. Simulink® displays an error message when the model updates.
Number of Iterations
— External value for iterator variableThe input port accepts data of mixed numeric types.
If the input port value is non-integer, it is first truncated to an integer.
Internally, the input value is cast to an integer of the type specified for the iteration variable output port.
If no output port is specified, the input port value is cast
to type int32
.
If the input port value exceeds the maximum value of the output port type, the overflow wraps around.
Data Types: single
| double
| int8
| int16
| int32
| uint8
| uint16
| uint32
Iterator value
— Value of iterator variable during time stepSelecting the Show iteration variable parameter check box adds an output port to this block.
Data Types: double
| int8
| int16
| int32
| uint8
| uint16
| uint32
States when starting
— Select block states between time stepsheld
(default) | reset
Select how to handle block states between time steps.
held
Hold block states between time steps. Block state values persist across time steps.
reset
Reset block states to their initial values at the beginning of each time step and before the first iteration loop.
Block Parameter:
ResetStates |
Type: character vector |
Values:
'held' | 'reset' |
Default:
'held' |
Iteration limit source
— Select source for number of iterationsinternal
(default) | external
Select source for number of iterations.
internal
Value of the Iteration limit parameter determines the number of iterations.
external
Value of the signal at the N port determines the number of iterations. The signal source must reside outside the For Iterator Subsystem block.
Selecting internal
displays and enables the
Iteration limit parameter. Selecting
external
adds an input port labeled
N.
Block Parameter:
IterationSource |
Type: character vector |
Values:
'internal' |
'external' |
Default:
'internal' |
Iteration limit
— Specify number of iterations5
(default) | integerSpecify the number of iterations. This parameter supports storage classes.
You can define the named constant in the base workspace of the Model
Explorer as a Simulink.Parameter
object
of the built-in storage class Define (custom)
type.
5
Iterate blocks in the For Iterator Subsystem
block 5
times.
Specify an integer or a named constant variable.
To enable this parameter, select internal
from the Iteration limit source drop-down
list.
Block Parameter:
IterationLimit |
Type: character vector |
Values: '5'
| '<integer>' |
Default:
'5' |
Set Next i (iteration variable) externally
— Control display of input port Control display of an input port.
Remove input port.
Add input port labeled Next_i for connecting to an external iteration variable source. The value of the input at the current iteration is used as the value of the iteration variable at the next iteration.
To enable this parameter, select the Show iteration variable parameter which also displays an output port labeled 1:N.
Block Parameter:
ExternalIncrement |
Type: character vector |
Values:
'off' | 'on' |
Default:
'off' |
Show iteration variable
— Control display of output portControl the display of an output port with the current iterator value for a loop.
Add output port labeled 1:N to the For Iterator block.
Remove output port.
Selecting this parameter enables the Set next i (iteration variable) externally parameter.
Block Parameter:
ShowIterationPort |
Type: character vector |
Value: 'on'
| 'off' |
Default:
'on' |
Index mode
— Select initial iteration numberOne-based
(default) | Zero-based
Select an initial iteration number of 0
or
1
.
One-based
Iteration number starts at one.
Zero-based
Iteration number starts at zero.
Block Parameter:
IndexMode |
Type: character vector |
Values:
'One-based' |
'Zero-based' |
Default:
'One-based' |
Iteration variable data type
— Select data typeint32
(default) | uint32
| int16
| uint16
| int8
| uint8
| double
Set the data type for the iteration value output from the iteration number port.
int32
Set data type to int32
.
uint32
Set data type to uint32
.
int16
Set data type to int16
.
uint16
Set data type to uint16
.
int8
Set data type to int8
.
uint8
Set data type to uint8
.
double
Set data type to double
.
Block Parameter:
IterationVariableDataType |
Type: character vector |
Value:
'int32' |
'uint32' |'int16' |
'uint16' |'int8' |
'uint8' |'double' |
Default:
'int32' |