1

Possible Duplicate:
Sort a matrix with another matrix

Given two matrices A and B of the same size, I want to sort A across the second dimension (rows) and apply the same ordering to the matrix B. Is it possible to vectorize this current code?

r = 10; c = 4;
A = rand(r,c);
B = reshape(1:r*c,c,r)';  % can be any random matrix'

[A,order] = sort(A,2);
for i=1:r
    B(i,:) = B(i,order(i,:));
end
Community
  • 1
  • 1
merv
  • 1,449
  • 3
  • 13
  • 25
  • 5
    This is a duplicate. Please have a look at the solutions and discussion in this question: [Sort a matrix with another matrix](http://stackoverflow.com/questions/2679022/sort-a-matrix-with-another-matrix) – Jonas Aug 26 '10 at 15:10
  • @Jonas: thanks, I guess vectorization isn't worth it in this case :) – merv Aug 26 '10 at 15:23

0 Answers0