MATLAB: How to reorder rows of a matrix to a given vector

alignreorder

Suppose I have a vector 'v' and a matrix 'A' as following: v = [3 5 1 2 4 6]';
A = [1 0 1 0 0 0 0; 2 0 0 0 0 1 0; 3 0 0 0 1 0 0; 4 0 0 0 0 0 1; 5 0 0 0 1 0 0; 6 0 0 1 0 0 0];
I want a matrix 'B' that reorders the rows of matrix 'A' into the given order of vector 'v'. So I want to get this: B = [3 3 0 0 0 1 0 0; 5 5 0 0 0 1 0 0; 1 1 0 1 0 0 0; 2 2 0 0 0 0 1 0; 4 4 0 0 0 0 0 1; 6 6 0 0 1 0 0 0]
How can I do that?

Best Answer

Robert - you could try doing
B = A(V,:)
to re-order your A given V.