$LastChangedDate: 27-Juil-2011 $

# CL_matSort

Matrix sorting by row or column

## Calling Sequence

       [B] = CL_matSort(A,num [,option,direction]);

## Description

- Sorts elements of a matrix.

  The matrix A can be considered as a set of column vectors or row vectors.

  If option is 'c', A is considered as a set of column vectors. num is then the number of the column to be sorted (by rows!). All the other columns are sorted accordingly.

  If option is 'r', A is considered as a set of row vectors. num is then the number of the row to be sorted (by columns!). All the other rows are sorted accordingly.

  The sorting order is determined by direction (increasing by default).

- Warning!

  The meaning of option may be confusing. The meaning is different from that of the 'option' argument of gsort.

## Parameters

A:

  Matrix (PxN)

num:

  Row or column number (1 x 1)

option:

  (string,optional) Indicates if num is a column number ('c') or row number ('r') Default is 'c'

direction:

  (string,optional) Sorting order: 'i' = increasing, 'd' = decreasing

B:

  Sorted matrix (PxN)

## Authors

- CNES - DCT/SB

## Examples

    A=[1,3,2;1000,1010,1020;10,80,15];
    // Sorts 2nd column increasingly, other columns sorted accordingly
    [B] = CL_matSort(A,2);

    // Sorts 3rd row decreasingly, other rows sorted accordingly
    [B] = CL_matSort(A,3,'r','d');