<< CL_sec2hms Utilities CL_unitConvert >>

CelestLab >> Utilities > CL_sortMat

CL_sortMat

Matrix rows or columns sorting

Calling Sequence

[mat2,I] = CL_sortMat(mat,u [,direction]);

Description

Parameters

mat:

Matrix (PxN)

u:

Row or column vector (1xN or Px1)

direction:

(string, optional) Sorting order: "i" = increasing, "d" = decreasing. Default is "i" (1x1)

mat2:

Sorted matrix (PxN)

I:

Sorting index (u_sorted = u(I)) (1xN or Px1)

Authors

Examples

mat = [1,3,2,4; 1000,1010,1020,990; 10,80,15,45];

// Re-arrange "mat" rows using "u" for sorting
u = [3;4;2];
[mat2,I] = CL_sortMat(mat,u);

// Sort 2nd row of "mat" decreasingly, other rows sorted accordingly
[mat2, I] = CL_sortMat(mat, mat(2,:), "d");
mat(:,I) - mat2;  // => 0

Report an issue
<< CL_sec2hms Utilities CL_unitConvert >>