ProductName  

Rearranges the columns or rows of the current matrix object according to a permutation index.

Syntax

MatrixObject.ReorderCols PermIndex
MatrixObject.ReorderRows PermIndex

Parameters

PermIndex
A variant containing an array of type Long Integer. Array elements should point to positions where matrix columns or rows are to be relocated.

Error Codes

Error 1304 is returned if PermIndex parameter does not contain a valid array.

Example

This example demonstrates the use of SortRows and ReorderRows method. Matrix A is sorted by its first column. The permutation index that results from SortRows method is used as input in ReorderRows method to reorder matrix B.
Private Sub MatrixSortReorderRows()

Dim A As Matrix, B As Matrix
Dim PI As Variant
    Set A = New Matrix
    A.Size 6, 6
    A.FillRandom
    
    Set B = New Matrix
    B.Size 6, 1
    B.FillRandom
    
    Debug.Print "A = "
    Debug.Print A.GetString
    Debug.Print "B = "
    Debug.Print B.GetString
    
    A.SortRows 0, msoAscending, PI
    B.ReorderRows PI

    Debug.Print "A sorted"
    Debug.Print A.GetString
    Debug.Print "B reordered"
    Debug.Print B.GetString
    
End Sub

Output

A = 
|  6.000  2.000  8.000  6.000  5.000  4.000 |
|  9.000  8.000  7.000  2.000  9.000  7.000 |
|  5.000  3.000  0.000  1.000  4.000  1.000 |
|  2.000 10.000  4.000  1.000  0.000  0.000 |
|  4.000  5.000  6.000  6.000  6.000  2.000 |
|  7.000  5.000  4.000  1.000  6.000  8.000 |

B = 
|  5.000 |
|  3.000 |
|  9.000 |
|  7.000 |
| 10.000 |
|  9.000 |

A sorted
|  2.000 10.000  4.000  1.000  0.000  0.000 |
|  4.000  5.000  6.000  6.000  6.000  2.000 |
|  5.000  3.000  0.000  1.000  4.000  1.000 |
|  6.000  2.000  8.000  6.000  5.000  4.000 |
|  7.000  5.000  4.000  1.000  6.000  8.000 |
|  9.000  8.000  7.000  2.000  9.000  7.000 |

B reordered
|  7.000 |
| 10.000 |
|  9.000 |
|  5.000 |
|  9.000 |
|  3.000 |

See Also

NormalizeMe Method

Applies To: Matrix | CMatrix