-5

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]
then 
   a=[3 7 2 8 1]
1
  • 8
    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
    Commented May 2, 2011 at 3:14

1 Answer 1

4

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

a = a(q);

Not the answer you're looking for? Browse other questions tagged or ask your own question.