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



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

Syntax

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

Parameters

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

Example

The following example uses the SortCols method to sort a matrix and then synchronizes a second matrix using the ReorderCols 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(3, 3)
        A.FillRandom()
        Dim B As Matrix = New Matrix(5, 3)
        B.FillRandom()

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

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

        Console.WriteLine("Matrix A sorted by 2nd row")
        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(3, 3);
        A.FillRandom();
        Matrix B = new Matrix(5, 3);
        B.FillRandom();

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

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

        Console.WriteLine("Matrix A sorted by 2nd row");
        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(array<System::String ^> ^args)
{
    //Declaring two random matrices
    Matrix^ A = gcnew Matrix(3, 3);
    A->FillRandom();
    Matrix^ B = gcnew Matrix(5, 3);
    B->FillRandom();

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

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

    Console::WriteLine("Matrix A sorted by 2nd row");
    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