Suppose I have a matrix A and I sort the rows of this matrix. How do I replicate the same ordering on a matrix B (same size of course)?
E.g.
A = rand(3,4);
[val ind] = sort(A,2);
B = rand(3,4);
%// Reorder the elements of B according the reordering of A
This is the best I've come up with
m = size(A,1);
B = B(bsxfun(@plus,(ind-1)*m,(1:m)'));
Out of curiosity, any alternatives?