IMatrix.CreateIterator

Syntax

CreateIterator: IMatrixIterator;

Description

The CreateIterator method creates an iterator that is used to navigate between matrix elements.

Comments

Use the IMatrix.CreateCoord method to create an object which is a matrix coordinate.

Example

To execute the example, add links to the MathFin and Matrix system assemblies.

Sub UserProc;
Var
    M: Matrix[
2];
    Mm: IMatrix;
    Iter: IMatrixIterator;
    Coord: IMatrixCoord;
    x, y: Integer;
Begin
    
For x := 0 To 4 Do
        
For y := 0 To 4 Do
            M[x, y] := Math.RandBetweenI(
09);
        
End For;
    
End For;
    Mm := M 
As IMatrix;
    Debug.WriteLine(
"Original matrix");
    Iter := Mm.CreateIterator;
    Iter.Move(IteratorDirection.First);
    
While Iter.Valid Do
        Debug.WriteLine(Iter.Value + 
" " + Iter.ValueFlag.ToString);
        Iter.Move(IteratorDirection.Next);
    
End While;
    Mm.ValueFlag := 
1;
    
//
    Coord := Mm.CreateCoord;
    Coord.Item(
0) := 0;
    Coord.Item(
1) := 0;
    Mm.Item(Coord) := 
11;
    Coord.Item(
0) := 2;
    Coord.Item(
1) := 2;
    Mm.Item(Coord) := 
13;
    
// value of the flag used in the matrix for marking changed values
    Mm.ValueFlag := 2;
    Coord.Item(
0) := 1;
    Coord.Item(
1) := 1;
    
// value of matrix element in the set coordinate
    Mm.Item(Coord) := 12;
    Coord.Item(
0) := 3;
    Coord.Item(
1) := 3;
    Mm.Item(Coord) := 
14;
    Debug.WriteLine(
"Before the flag is changed");
    Iter.Move(IteratorDirection.First);
    
While Iter.Valid Do
        Debug.WriteLine(Iter.Value + 
" " + Iter.ValueFlag.ToString);
        Iter.Move(IteratorDirection.Next);
    
End While;
    
// changing of flag
    Mm.ChangeValueFlag(110);
    Debug.WriteLine(
"After the flag is changed");
    Iter := Mm.CreateIterator;
    Iter.Move(IteratorDirection.First);
    
While Iter.Valid Do
        Debug.WriteLine(Iter.Value + 
" " + Iter.ValueFlag.ToString);
        Iter.Move(IteratorDirection.Next);
    
End While;
End Sub UserProc;

After executing the example a matrix with random values is created. Values of four diagonal elements are updated in this matrix. Values are changed with different flag. After this, flag value of the elements, that were changed with matrix flag 1 changes to 10. Elements values and their corresponding flags are displayed in the development environment console.

See also:

IMatrix