I have two vectors, a and b, of the same length, each having some random order. I want a to have its same order, and for b to be sorted according to a.
So for example:
a = [5 4 1 2]
b = [7 8 9 6]
now I want the highest value of b to be in the position of the highest value of a, and the second highest value of b to be in the position of the second highest value of a, etc; that is:
b = [9 8 6 7]
I have tried
[~, indices] = sort(a)
b(indices)
but this yields
ans = [9 6 8 7]
which is clearly not right.
Any suggestions?
a's original order.