.NET Matrix Library
ReorderRows Method
See Also  Example Send Feedback



pivots
An array of integers containing the row dispositions.
Reorders matrix rows according to the specified order.

Syntax

Visual Basic (Declaration) 
Public Sub ReorderRows( _
   ByVal pivots() As Integer _
) 
Visual Basic (Usage)Copy Code
Dim instance As Matrix
Dim pivots() As Integer
 
instance.ReorderRows(pivots)
C# 
public void ReorderRows( 
   int[] pivots
)
C++/CLI 
public:
void ReorderRows( 
   array<int>^ pivots
) 

Parameters

pivots
An array of integers containing the row dispositions.

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;
}

Remarks

pivots[i] = k denotes that row i should be moved to position k.

Requirements

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

See Also

.NET Matrix Library