MATLAB: Sorting a matrix in descending order

MATLABsort

I have a matrix
group =
0 0 0 1
0 1 0 0
0 0 1 0
0 1 0 0
0 0 0 1
0 0 1 0
0 0 1 0
0 1 0 0
0 0 0 1
0 1 0 0
1 0 0 0
0 1 0 0
if I want to sort in ascending order I can use
sortrows(group)
ans =
0 0 0 1
0 0 0 1
0 0 0 1
0 0 1 0
0 0 1 0
0 0 1 0
0 1 0 0
0 1 0 0
0 1 0 0
0 1 0 0
0 1 0 0
1 0 0 0
but I want to sort in descending order. What to do?

Best Answer

You can use a second input argument. By omitting it, you have effectively used
sortrows(group,[1 2 3 4])
for the ascending case. I believe what you want for the descending case is
sortrows(group,[-1 -2 -3 -4])
but you should verify that the result.