JohnnyF
JohnnyF

Reputation: 1101

MATLAB sort matrix by one row

I have matrix lets say MAT of size 2*n

I want to sort the matrix by row num 2

BUT to keep each info from row 1 to its row 2 info

prev
C K A L E Y B
4 2 1 3 6 7 7

and after sort
A K L C E Y B
1 2 3 4 6 7 7

any idea?

Upvotes: 0

Views: 106

Answers (1)

Shai
Shai

Reputation: 114786

you can use the second output argument of sort:

[~, si] = sort(MAT(2,:));
res = MAT(:,si);

Upvotes: 1

Related Questions