.NET Matrix Library
SortCols Method
See Also  Example Send Feedback



Sorts the columns of the current matrix. Sorts the columns of the current matrix.

Overload List

OverloadDescription
SortCols()Sorts the columns of the current matrix by the elements of its first row in ascending order.  
SortCols(Int32)Sorts the columns of the current matrix by the elements of the specified row in ascending order.  
SortCols(Int32,SortOrder)Sorts the columns of the current matrix by the elements of the specified row in ascending or descending order.  
SortCols(Int32,SortOrder,Int32[])Sorts the columns of the current matrix by the elements of the specified row in ascending or descending order and returns the columns' dispositions.  

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