CreateIterator: IMatrixIterator;
CreateIterator: Prognoz.Platform.Interop.Matrix.IMatrixIterator;
The CreateIterator method creates an iterator that is used to navigate between matrix elements.
Use the IMatrix.CreateCoord method to create an object which is a matrix coordinate.
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(0, 9);
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(1, 10);
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.
To execute the example, add links to the MathFin, Matrix and ForeSystem system assemblies.
Imports Prognoz.Platform.Interop.MathFin;
Imports Prognoz.Platform.Interop.Matrix;
Imports Prognoz.Platform.Interop.ForeSystem;
…
Public Shared Sub Main(Params: StartParams);
Var
//M: Matrix[2];
M: Array;
Mm: IMatrix;
Iter: IMatrixIterator;
Coord: IMatrixCoord;
Math: MathClass = New MathClass();
x, y: Integer;
Begin
For x := 0 To 4 Do
For y := 0 To 4 Do
M[x, y] := Math.RandBetweenI(0, 9);
End For;
End For;
Mm := M As IMatrix;
System.Diagnostics.Debug.WriteLine("Source matrix");
Iter := Mm.CreateIterator();
Iter.Move(IteratorDirection.itdFirst);
While Iter.Valid Do
System.Diagnostics.Debug.WriteLine(Iter.Value + " " + Iter.ValueFlag.ToString());
Iter.Move(IteratorDirection.itdLast);
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 to mark 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;
System.Diagnostics.Debug.WriteLine("Before the flag is changed");
Iter.Move(IteratorDirection.itdFirst);
While Iter.Valid Do
System.Diagnostics.Debug.WriteLine(Iter.Value + " " + Iter.ValueFlag.ToString());
Iter.Move(IteratorDirection.itdNext);
End While;
// change flag
Mm.ChangeValueFlag(1, 10);
System.Diagnostics.Debug.WriteLine("After the flag is changed");
Iter := Mm.CreateIterator();
Iter.Move(IteratorDirection.itdFirst);
While Iter.Valid Do
System.Diagnostics.Debug.WriteLine(Iter.Value + " " + Iter.ValueFlag.ToString());
Iter.Move(IteratorDirection.itdNext);
End While;
End Sub;
See also: