Take the 2-minute tour ×

I have an array to order it as stated in the other array (the second array is the indices that i want the first array to be ordered in )

if a=[2 3 1 8 7]
   q=[2 5 1 4 3]
   a=[3 7 2 8 1]
share|improve this question
Some advice: you previously asked a question about sorting in MATLAB, and you were pointed towards the help documentation. Had you actually read that documentation, you would have already had your answer to this question. I understand if you are new to MATLAB and learning it yourself, but you should really put more effort into reading the help docs first, and only asking questions here when you are stuck. Stack Overflow isn't here to do all your thinking for you. –  gnovice May 2 '11 at 3:14

1 Answer 1

You can use the second array to index into the first:

a = a(q);
share|improve this answer

Your Answer


