IMatrixModel.Sort

Syntax

Sort(Coord: IMatrixModelCoord; Ascending: Boolean);

Parameters

Coord. Coordinate in dimension, by which the slice is taken. Sorting is executed by slice values.

Ascending. The parameter that determines sorting direction. If this parameter is set to True, the values are sorted in ascending order.

Description

The Sort method sorts matrix contents depending on the values that are contained in the Coord slice.

Comments

After the method is applied, coordinates of matrix elements are rearranged in such a way that the values of the Coord slice are arranged depending on the sorting direction specified in the Ascending parameter.

NOTE. This method is supported only for the matrices that are objects of the Matrix class and are created using the Fore language. The method cannot be applied to matrices obtained as a result of calculation of the platform's objects (output matrices of cubes, matrices obtained when working with a modeling container or time series database, matrices of slices in regular reports).

Example

Sub Main;

Var

M: Matrix[2];

Mm: IMatrixModel;

C: IMatrixModelCoord;

I, J: Integer;

Begin

Debug.WriteLine("Source matrix");

For i := 0 To 3 Do

For j := 0 To 3 Do

M[i, j] := Math.RandBetweenI(0, 9);

Debug.Write(M[i, j] + " ");

End For;

Debug.WriteLine("");

End For;

Mm := M As IMatrixModel;

C := Mm.CreateModelCoord;

C.Item(0) := 0; // To sort columns by values of the first row

//C.Item(1) := 3; // To sort rows by values of the fourth column

Mm.Sort(C, True);

Debug.WriteLine("");

Debug.WriteLine("Sorted matrix");

For i := 0 To 3 Do

For j := 0 To 3 Do

Debug.Write(M[i, j] + " ");

End For;

Debug.WriteLine("");

End For;

End Sub Main;

On executing the example the system creates a two-dimensional matrix with random integer values. Matrix columns are sorted so that the values of the first row were positioned in ascending order.

See also:

IMatrixModel