MATLAB: Index of reordered vector

indexing

Hi all
I better ask my question directly through example
Suppose A = [1 2 3 4 5 6] and I reorder the vector A to get AR = [ 2 4 1 6 5 3]. Now, I wish to track the position of elements of A in AR (i.e. I wish to get vector P = [3 1 6 2 5 4]) so that I can get original vector A by renumbering AR using P (i.e. AO = AR(P) so that A=AO); how can I get vector P?
Regards N Madani SYED

Best Answer

A = [1 2 3 4 5 6]
AR = [2 4 1 6 5 3]
[junk, P] = ismember(A, AR)