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.
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)