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.

Description

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

Comments

If Ascending parameter is set to True, sorting is ascending.

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

Add a link to the MathFin system assembly.

Sub UserProc;
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(09);
            Debug.Write(M[i, j] + " ");
        End For;
        Debug.WriteLine("");
    End For;
    Mm := M As IMatrixModel;
    C := Mm.CreateModelCoord;
    C.Item(0) := 0// For column sorting by values of the first row
    //C.Item(1) := 3; // For row sorting 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 UserProc;

After 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