Simulink Reference Previous page   Next Page
For Iterator

Repeatedly execute the contents of a subsystem at the current time step until an iteration variable exceeds a specified iteration limit.

Library

Ports & Subsystems/For Iterator Subsystem

Description


The For Iterator block, when placed in a subsystem, repeatedly executes the contents of the subsystem at the current time step until an iteration variable exceeds a specified iteration limit. You can use this block to implement the block diagram equivalent of a for loop in the C programming language.

The block's parameter dialog allows you to specify the maximum value of the iteration variable or an external source for the maximum value and an optional external source for the next value of the iteration variable. If you do not specify an external source for the next value of the iteration variable, the next value is determined by incrementing the current value:

The model in the following figure uses a For Iterator block to increment an initial value of zero by 10 over 20 iterations at every time step.

The following figure shows the result.

The For Iterator subsystem in this example is equivalent to the following C code.

Data Type Support

The following rules apply to the data type of the number of iterations (N) input port:

Data output for the iterator value can be selected as double, int32, int16, or int8 in the Block Properties dialog.

The following rules apply to the iteration variable input port.

Parameters and Dialog Box

States when starting
Set this field to reset if you want the states of the For subsystem to be reinitialized before the first iteration at each time step. Otherwise, set this field to held (the default) to make sure that these subsystem states retain their values from the last iteration at the previous time step.
Iteration limit source
If you set this field to internal, the value of the Number of iterations field determines the number of iterations. If you set this field to external, the signal at the For Iterator block's N port determines the number of iterations. The iteration limit source must reside outside the For Iterator subsystem.
Iteration limit
Set the number of iterations for the For Iterator block to this value. This field appears only if you selected internal for the Source of number of iterations field.
Set next i (iteration variable) externally
This option can be selected only if you select the Show iteration variable option. If you select this option, the For Iterator block displays an additional input for connecting 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.
Show iteration variable
If you select this check box, the For Iterator block outputs its iteration value.
Output data type
Set the type for the iteration value output from the iteration number port to double, int32, int16, or int8.

Characteristics

Direct Feedthrough
No
Sample Time
Inherited from driving blocks
Scalar Expansion
No
Dimensionalized
No
Zero Crossing
No


Previous page  Fixed-Point State-Space For Iterator Subsystem Next page

© 1994-2005 The MathWorks, Inc.