HOW CAN I SORTED MY MATRIX DESCEND

I HAVE A MATRIX M=[ 1 2 3 4 5 ;1 20 54 6 40] I WANT TO SORT MY MATRIX WITHIN THE SECOND COLON WITH ASCENDING WAY TO OBTEIND THIS RESULT :
M=[3 5 2 4 1;54 40 20 6 1]
HOW CAN I DO

 Accepted Answer

Andrei Bobrov
Andrei Bobrov on 22 Nov 2015
Edited: Andrei Bobrov on 22 Nov 2015
M=[ 1 2 3 4 5 ;1 20 54 6 40];
[~,ii] = sort(M(2,:),'descend');
out = M(:,ii);
or
out = sortrows(M',-2)';

1 Comment

thank you i use out = sortrows(M',-2)'; its good :)

Sign in to comment.

More Answers (0)

Categories

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!