Re: Following position change in different vectors
- To: mathgroup at smc.vnet.net
 - Subject: [mg117538] Re: Following position change in different vectors
 - From: Szabolcs Horvát <szhorvat at gmail.com>
 - Date: Tue, 22 Mar 2011 05:06:52 -0500 (EST)
 - References: <im4iqj$d1b$1@smc.vnet.net>
 
On 2011.03.20. 10:53, Lengyel Tamas 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)
>
Either use Ordering[]:
order = Ordering[v1]
v1[[order]]
v2[[order]]
or group them together:
Transpose@Sort@Transpose[{v1, v2}]