.NET Matrix Library
SortRows(Int32,SortOrder) Method
See Also  Example Send Feedback



col
An integer specifying the column by which to sort the matrix row.
order
A SortOrder enumeration value specifying ascending or descending order.
Sorts the rows of the current matrix by the elements of the specified column in ascending or descending order.

Syntax

Visual Basic (Declaration) 
Public Overloads Sub SortRows( _
   ByVal col As Integer, _
   ByVal order As SortOrder _
) 
Visual Basic (Usage)Copy Code
Dim instance As Matrix
Dim col As Integer
Dim order As SortOrder
 
instance.SortRows(col, order)
C# 
public void SortRows( 
   int col,
   SortOrder order
)
C++/CLI 
public:
void SortRows( 
   int col,
   SortOrder order
) 

Parameters

col
An integer specifying the column by which to sort the matrix row.
order
A SortOrder enumeration value specifying ascending or descending order.

Example

The following example uses the SortRows method to sort a matrix and then synchronizes a second matrix using the ReorderRows method.
Visual BasicCopy Code
Imports System
Imports Bluebit.MatrixLibrary

Class Test

    Public Shared Sub Main()

        'Declaring two random matrices
        Dim A As Matrix = New Matrix(4, 3)
        A.FillRandom()
        Dim B As Matrix = New Matrix(4, 3)
        B.FillRandom()

        Console.WriteLine("Matrix A =")
        Console.WriteLine(A)
        Console.WriteLine("Matrix B =")
        Console.WriteLine(B)

        Dim pivots() As Integer
        'sort the rows of matrix A in descending order
        'by the elements of its second columns (column #1)
        A.SortRows(1, SortOrder.Descending, pivots)
        'use the pivots to syncronize matrix B with A
        B.ReorderRows(pivots)

        Console.WriteLine("Matrix A sorted by 2nd column")
        Console.WriteLine(A)
        Console.WriteLine("Matrix B synchronized with A")
        Console.WriteLine(B)

        Console.Read()

    End Sub

End Class
C#Copy Code
using System;
using Bluebit.MatrixLibrary;

class Test
{
    static void Main(string[] args)
    {
        //Declaring two random matrices
        Matrix A = new Matrix(4, 3);
        A.FillRandom();
        Matrix B = new Matrix(4, 3);
        B.FillRandom();

        Console.WriteLine("Matrix A =");
        Console.WriteLine(A);
        Console.WriteLine("Matrix B =");
        Console.WriteLine(B);

        int[] pivots ;
        //sort the rows of matrix A in descending order
        //by the elements of its second column (column #1)
        A.SortRows(1, SortOrder.Descending, out pivots);
        //use the pivots to syncronize matrix B with A
        B.ReorderRows(pivots);

        Console.WriteLine("Matrix A sorted by 2nd column");
        Console.WriteLine(A);
        Console.WriteLine("Matrix B synchronized with A");
        Console.WriteLine(B);

        Console.Read();
    }
}
C++Copy Code
#include "stdafx.h"

using namespace System;
using namespace Bluebit::MatrixLibrary;

int main() 
{
    //Declaring two random matrices
    Matrix^ A = gcnew Matrix(4, 3);
    A->FillRandom();
    Matrix^ B = gcnew Matrix(4, 3);
    B->FillRandom();

    Console::WriteLine("Matrix A =");
    Console::WriteLine(A);
    Console::WriteLine("Matrix B =");
    Console::WriteLine(B);

    array<int> ^pivots;
    //sort the rows of matrix A in descending order
    //by the elements of its second column (column #1)
    A->SortRows(1, SortOrder::Descending, pivots);
    //use the pivots to syncronize matrix B with A
    B->ReorderRows(pivots);

    Console::WriteLine("Matrix A sorted by 2nd column");
    Console::WriteLine(A);
    Console::WriteLine("Matrix B synchronized with A");
    Console::WriteLine(B);

    Console::Read();
    
	return 0;
}

Requirements

Target Platforms: Windows 2000, Windows XP, Windows Server 2003 family, Windows Vista, Windows Server 2008 family, Windows 7

See Also

.NET Matrix Library