       Re: Following position change in different vectors

• To: mathgroup at smc.vnet.net
• Subject: [mg117522] Re: Following position change in different vectors
• From: István Zachar <zac at freemail.hu>
• Date: Mon, 21 Mar 2011 06:17:44 -0500 (EST)
• References: <im4iqj\$d1b\$1@smc.vnet.net>

```Dear Tam=E1s,

If I understand correctly, this might help:

In:= n = 10;
v1 = RandomSample[Range, n]

Out= {6, 3, 14, 18, 19, 11, 12, 15, 9, 2}

In:= v2 = Map[a, v1]

Out= {a, a, a, a, a, a, a, a, a,
a}

In:= order = Ordering[v1]

Out= {10, 2, 1, 9, 6, 7, 3, 8, 4, 5}

In:= Sort[v1]

Out= {2, 3, 6, 9, 11, 12, 14, 15, 18, 19}

In:= Part[v2, order]

Out= {a, a, a, a, a, a, a, a, a,
a}

Note that function 'a' can be anything, the sorting of v2 solely
depends on the ordering of v1!

Istv=E1n

On Mar 20, 10:53 am, Lengyel Tamas <lt... at hszk.bme.hu> wrote:
> Dear Mathworld Users,
>
> Sorry for asking your help again, I hope I'm not spamming too much.
> My problem is the following:
>
> 1) I have 2 vectors with equal length. The positions of the first vector
> correspond to the second vector. So the first element of v2 is calculated
> from the first element of v1, etc.
>
> 2) I wish to sort the first vector in ascending magnitude using Sort[v1].
> Naturally the positions of v1's elements change.
>
> What I want is the same change of position in v2's positions.
>
> (So e.g. if v1's sixth element moves after Sort to  the first position,
> I'd like v2's same position element to follow suit)
>