Given matrix
as follows
300 48 2
500 23 5
120 55 7
40 32 1
Need to sort it based on entries in the second column.
EDU>> [v,I]=sort(A(:,2));
EDU>> B=A(I,:)
B =
500 23 5
40 32 1
300 48 2
120 55 7
a={{300,48,2},{500,23,5},{120,55,7},{40,32,1}};
b=SortBy[a, #[[2]]&]
Out[9]= {{500,23,5},{40,32,1},{300,48,2},{120,55,7}}