Re: Following position change in different vectors
- To: mathgroup at smc.vnet.net
- Subject: [mg117503] Re: Following position change in different vectors
- From: DrMajorBob <btreat1 at austin.rr.com>
- Date: Mon, 21 Mar 2011 06:14:08 -0500 (EST)
To sort two lists v1 and v2 in the same order (based on v1):
v1 = RandomReal[1, 10]
v2 = RandomReal[1, 10]
{0.829411, 0.341577, 0.418077, 0.450313, 0.448381, 0.936902, \
0.506362, 0.348812, 0.783363, 0.84515}
{0.0563887, 0.797678, 0.448193, 0.753381, 0.719462, 0.875357, \
0.587446, 0.0171445, 0.159417, 0.812329}
sv1 = v1[[o = Ordering@v1]]
sv2 = v2[[o]]
{0.341577, 0.348812, 0.418077, 0.448381, 0.450313, 0.506362, \
0.783363, 0.829411, 0.84515, 0.936902}
{0.797678, 0.0171445, 0.448193, 0.719462, 0.753381, 0.587446, \
0.159417, 0.0563887, 0.812329, 0.875357}
Bobby
On Sun, 20 Mar 2011 04:53:00 -0500, Lengyel Tamas <lt648 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)
>
> Thank you for your help in advance.
>
> Tamas
>
--
DrMajorBob at yahoo.com