MATLAB Answers

0

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

Asked by sushmita sharma on 15 Jun 2018
Latest activity Commented on by Jan
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

Sign in to comment.

Tags

1 Answer

Answer by Jan
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)

  2 Comments

I want to sort the column matrix with its previous location

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.

Sign in to comment.