MATLAB: Is there any one who can help for the following matrix problem

homeworksorting

I have 3X6 matrix:
M=[15 18 14 19 17 14;
30 3 8 14 1 5;
7 16 13 11 20 2] ;
It is required to sort them using only one of the smallest value in the column (i.e. the column which contain the smallest value should be first column in the matrix without change the order of original column). The sorted output should be displayed as:
M=[17 14 18 19 15 14;
1 5 3 4 30 8;
20 2 16 11 7 13];
Since the value 1 is the smallest value in column 5 at the original matrix, it comes in the first column for sorted output matrix.

Best Answer

I think this is the way to do it. Your expected output has typo in it.
M=[15 18 14 19 17 14;
30 3 8 14 1 5;
7 16 13 11 20 2] ;
MinM=min(M);
[~,Index]=sort(MinM);
NewM=M(:,Index)
NewM =
17 14 18 15 14 19
1 5 3 30 8 14
20 2 16 7 13 11