IMatrix.SwapTo

Syntax

SwapTo(Dims: IDimSelectionSet): IMatrix;

Parameters

Dims - dimensions selection, according to which dimensions are swapped in a matrix.

Description

The SwapTo method swaps dimensions with data in a matrix. Dimensions are swapped according to the elements selection passed by the Dims parameter.

Example

Executing the example requires a cube with the Cube_1 identifier that contains three dimensions.

Sub Main;

Var

MB: IMetabase;

Cube: ICubeInstance;

DefDes: ICubeInstanceDestination;

Matr, Matr1: IMatrix;

DimSS, DimSS1: IDimSelectionSet;

SSFact: IDimSelectionSetFactory;

DimS: IDimSelection;

i, x, y, z: Integer;

M: Matrix[3];

Begin

MB := MetabaseClass.Active;

Cube := MB.ItemById("Cube_1").Open(Null) As ICubeInstance;

DefDes := Cube.Destinations.DefaultDestination;

DimSS := DefDes.CreateDimSelectionSet;

For Each DimS In DimSS Do

DimS.SelectAll;

End For;

SSFact := New DimSelectionSetFactory.Create;

DimSS1 := SSFact.CreateDimSelectionSet;

//Selection of dimensions arranged in inverse order

For i := DimSS.Count - 1 To 0 Step - 1 Do

DimSS1.Add(DimSS.Item(i).Dimension);

End For;

For Each DimS In DimSS1 Do

DimS.SelectAll;

End For;

//Source matrix

Matr := DefDes.Execute(DimSS);

//Matrix with swapped dimensions

Matr1 := Matr.SwapTo(DimSS1);

M := Matr;

Debug.WriteLine("Source matrix");

For x := Matr.LowerBound(0) To Matr.UpperBound(0) Do

For y := Matr.LowerBound(1) To Matr.UpperBound(1) Do

For z := Matr.LowerBound(2) To Matr.UpperBound(2) Do

Debug.Write(M[x, y, z] + " ");

End For;

Debug.WriteLine("");

End For;

Debug.WriteLine("");

End For;

M := Matr1;

Debug.WriteLine("Matrix with swapped dimensions");

For x := Matr1.LowerBound(0) To Matr1.UpperBound(0) Do

For y := Matr1.LowerBound(1) To Matr1.UpperBound(1) Do

For z := Matr1.LowerBound(2) To Matr1.UpperBound(2) Do

Debug.Write(M[x, y, z] + " ");

End For;

Debug.WriteLine("");

End For;

Debug.WriteLine("");

End For;

End Sub Main;

After executing the example a matrix with data is created on the basis of a cube. After dimensions are swapped in inverse order, another matrix with data is created. Elements values of both matrices are displayed in the development environment console.

See also:

IMatrix