Say I have a vector,
V = [2 5 4 1 3]
and I want to use the numbers of the vector itself to index. Starting from 1, I go to the first element in V; which = 2.
From there, I want to go to the 2nd element of V–5, then 3, then 4, and finally 1.
How would I go about extracting Vnew = [1 2 4 5 3]?
So far I've tried:
V(V) = [5 3 1 2 4]
I'm assuming it'll require some sort of loop but I'm completely stumped right now.
EDIT: Apologies for the confusion in the explanation above; I don't need the produced vector, but the order in which it's produced–if that makes any sense.
Starting at index 1 of V, I get 2. Then I use 2 as the index of V to get 5–use 5 to get 3–3 for 4—4 loops back to 1.
The part I need is the order in which I loop through. The first index will always be 1, but say the first element of V was 3. I'd then go to the THIRD element of V and Vnew for the third element would equal 2. Using this method, I need to output Vnew = [1 2 4 5 3].
Best Answer