# 2.2.3.9.68 matrixbase::Sort

## Description

Sort a matrix in row order (across rows from top/left to bottom/right).

## Syntax

void Sort( BOOL bAscending = TRUE )

## Parameters

bAscending
[input] Sort in ascending order if TRUE otherwise sort in descending order

## Examples

EX1

// Sort cell values in a matrix
void matrixbase_Sort_ex1()
{
int ii,jj;

matrix<double> mat1 = {
{-2,  1,  5},
{-1,  2,  6},
{99,  3,  7},
{ 0,  4,  8}
};
for(ii=0; ii<3; ii++)
for(jj=0; jj<2; jj++)
if(mat1[ii][jj]==99)
mat1[ii][jj]=NANUM;  // set row=ii,col=jj to NANUM
// Output of this sample code:
//   Sort matrix is:
//        {-2, -1, --}
//        { 0,  1,  2}
//        { 3,  4,  5}
//        { 6,  7,  8}
//
MatrixPage MatPg1;
MatPg1.Create("Origin");
MatrixLayer MatLy1 = MatPg1.Layers(0);
Matrix Mat1(MatLy1);
Mat1 = mat1;
printf("  Input matrix is %s.\n",Mat1.GetName());

MatrixPage MatPg2;
MatPg2.Create("Origin");
MatrixLayer MatLy2 = MatPg2.Layers(0);
Matrix Mat2(MatLy2);
Mat2 = mat1;

Mat2.Sort();

printf("  Sorted matrix is %s.\n",Mat2.GetName());
printf("  Note that the missing value is treated as a small negative number.\n");
printf("  Note that this function does not maintain the row wise integrity.\n");
}