## how to mind the nth max or min value of a column matrix with its location

Asked by sushmita sharma

### sushmita sharma (view profile)

on 15 Jun 2018
Latest activity Commented on by Jan

### Jan (view profile)

on 16 Jun 2018
suppose I have one a=nXm matrix and the the function values of a is saved in another matrix b. Now I want to sort matrix a on basis of their function evaluation. or how can I get the nth max or min values of matrix b with the position.

#### 1 Comment

Stephen Cobeldick

### Stephen Cobeldick (view profile)

on 15 Jun 2018
sort and get its second output argument.

### Jan (view profile)

on 15 Jun 2018

a = rand(3,4);
b = sin(a);
[bs, index] = sort(b, 2); % If you want to sort along the rows
s = size(a);
indexL = sub2ind(s, repmat((1:s(1)).', 1, s(2)), index);
as = a(indexL)

sushmita sharma

### sushmita sharma (view profile)

on 15 Jun 2018
I want to sort the column matrix with its previous location
Jan

### Jan (view profile)

on 16 Jun 2018
What does this mean? Are you able to transfer my suggestion to operate along the columns?
a = rand(3,4);
b = sin(a);
[bs, index] = sort(b, 1); % If you want to sort along the columns
s = size(a);
indexL = sub2ind(s, index, repmat(1:s(2), s(1), 1));
as = a(indexL)
What is "the previous location"? The less the readers have to guess, the easier and more likely matching is the answer.