Transform: IMatrix;
The Transform method transforms matrix transformer data to matrix.
To transform data from matrix transformer to matrix, add or remove time dimensions from the collection by means of the IMatrixTransformerDimensions.Add or IMatrixTransformerDimensions.Remove methods.
Executing the example requires that the repository contains a calendar dictionary with the D_CALENDAR identifier.
Add links to the Dimensions, MthFin, Matrix, and Metabase system assemblies.
Sub UserProc;
Var
MB: IMetabase;
DimA: IDimInstance;
Mfactory: IMatrixFactory;
DimSel: IDimSelectionSet;
Dfactory: IDimSelectionSetFactory;
Matrix, NewMat: IMatrix;
i1, i, element: integer;
Coord: IMatrixCoord;
elements: IDimElements;
Selection: IDimSelection;
Iterator: IMatrixIterator;
trf: IMatrixTransformer;
mtd: IMatrixTransformerDimension;
Begin
// Get repository
MB := MetabaseClass.Active;
// Get dictionary data
DimA := MB.ItemById("D_CALENDAR").Open(Null) As IDimInstance;
// Create selection
Dfactory := New DimSelectionSetFactory.Create;
DimSel := Dfactory.CreateDimSelectionSet;
DimSel.Add(DimA);
// Create matrix and fill it
Mfactory := New MatrixFactory.Create As IMatrixFactory;
Matrix := Mfactory.CreateMatrix(DimSel);
Coord := Matrix.CreateCoord;
For i1 := 0 To DimSel.Item(0).Dimension.Elements.Count - 1 Do
Coord.Item(0) := i1;
Matrix.Item(Coord) := Math.RandBetweenI(0, 12);
End For;
// Display coordinates to the console window
For i := 0 To DimSel.Count - 1 Do
elements := DimSel.Item(i).Dimension.Elements;
element := coord.Item(i);
If element <> -1 Then
Debug.WriteLine(element.ToString + " = (" + elements.Name(element) + ") -- ");
End If;
End For;
// Display obtained matrix to the console window
Debug.WriteLine("Matrix: ");
Selection := DimSel.Item(0);
For Each Selection In Matrix.Dimensions Do
// Display dimensions and their keys
Debug.WriteLine(" Dimension - " + selection.Dimension.Name + "; Key = " + selection.Dimension.Key.ToString);
// Display dimension elements
Debug.WriteLine(" Elements: ");
For i := 0 To Selection.Dimension.Elements.Count - 1 Do
Debug.WriteLine(" " + selection.Dimension.Elements.Name(i));
End For;
End For;
// Display values
Debug.WriteLine("Matrix values: ");
Iterator := matrix.CreateIterator;
Coord := matrix.CreateCoord;
Iterator.Move(IteratorDirection.First);
While Iterator.Valid Do
Iterator.PutCurrentPos(Coord);
Debug.WriteLine(" Value = " + Iterator.Value As String);
Iterator.Move(IteratorDirection.Next);
End While;
// Create matrix transformer
trf := New MatrixTransformer.Create;
trf.Source := Matrix;
// Add two new time dimensions
trf.Dimensions.Add(0, 3);
trf.Dimensions.Add(0, 2);
// Get a new matrix
NewMat := trf.Transform;
Debug.WriteLine("Number of values in new matrix = " + NewMat.ValueCount.ToString);
// Get time dimensions
For i := 0 To trf.Dimensions.Count - 1 Do
mtd := trf.Dimensions.Item(i);
If Not mtd.MatchCase Then
mtd.MatchCase := True;
End If;
// Display to the console window
Debug.WriteLine("Time dimension of new matrix: ");
Debug.WriteLine
("Dimension index - " + mtd.Index.ToString + "; " + "Dimension - " + mtd.Dimension.Name + "; " + "Element - " + mtd.Element.ToString);
End For;
End Sub UserProc;
After executing the example the console window displays:
Dimension, key, elements, values of matrix calendar dimension.
Number of values in the new obtained matrix.
Data of time dimensions of the new matrix.
See also: