This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

For Iterator

Repeat execution of a subsystem during a time step for a specified number of iterations

  • Library:
  • Ports & Subsystems

Description

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.

Ports

Input

expand all

  • The 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

Output

expand all

Selecting the Show iteration variable parameter check box adds an output port to this block.

Data Types: double | int8 | int16 | int32

Parameters

expand all

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.

Programmatic Use

Block Parameter: ResetStates
Type: character vector
Values: 'held' | 'reset'
Default: 'held'

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.

Dependencies

Selecting internal displays and enables the Iteration limit parameter. Selecting external adds an input port labeled N.

Programmatic Use

Block Parameter: IterationSource
Type: character vector
Values: 'internal' | 'external'
Default: 'internal'

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

integer

Specify an integer or a named constant variable.

Dependencies

To enable this parameter, select internal from the Iteration limit source drop-down list.

Programmatic Use

Block Parameter: IterationLimit
Type: character vector
Values: '5' | '<integer>'
Default: '5'

Control display of an input port.

off

Remove input port.

on

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.

Dependencies

To enable this parameter, select the Show iteration variable parameter which also displays an output port labeled 1:N.

Programmatic Use

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

Control the display of an output port with the current iterator value for a loop.

on

Add output port labeled 1:N to the For Iterator block.

off

Remove output port.

Dependencies

Selecting this parameter enables the Set next i (iteration variable) externally parameter.

Programmatic Use

Block Parameter: ShowIterationPort
Type: character vector
Value: 'on' | 'off'
Default: 'on'

Select an initial iteration number of 0 or 1.

One-based

Iteration number starts at one.

Zero-based

Iteration number starts at zero.

Programmatic Use

Block Parameter: IndexMode
Type: character vector
Values: 'One-based' | 'Zero-based'
Default: 'One-based'

Set the data type for the iteration value output from the iteration number port.

int32

Set data type to int32.

int16

Set data type to int16.

int8

Set data type to int8.

double

Set data type to double.

Programmatic Use

Block Parameter: IterationVariableDataType
Type: character vector
Value: 'int32' | 'int16' | 'int8' | 'double'
Default: 'int32'

Introduced before R2006a