<< 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:

(optional) Row or column vector (1xN or Px1) or empty. Default is empty

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);
mat(I,:) - mat2  // => 0

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

// Sort a row or column vector (increasing order by default)
vec = mat(:);
[vec2, I] = CL_sortMat(vec);
vec(I) - vec2  // => 0

Report an issue
<< CL_sec2hms Utilities CL_unitConvert >>