MathGroup Archive 2006

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Can anybody help?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63528] Re: [mg63519] Can anybody help?
  • From: ggroup at sarj.ca
  • Date: Tue, 3 Jan 2006 05:24:43 -0500 (EST)
  • References: <200601030626.BAA26066@smc.vnet.net>
  • Reply-to: ggroup at sarj.ca
  • Sender: owner-wri-mathgroup at wolfram.com

On Tuesday, January 3, 2006 at 01:26 GMT -0500, Kent Holing wrote:

> I have three vecors containg: v1, v2 and v3.
> v1 and v2 has the same length. v3 is shorter than v1.
> All elements of v3 is an element of v1.
> Need to have the corresponding v2 values corresponding to the v3 (=
> v1) value.
> Know that the elements of v1 and v3 are different. The elements of
> v2 do not need to different.

Unfortunately your requirement isn't entirely clear:  Your example
either has an error in the example output, or it doesn't seem to match
my reading of your requirement.

I assume you mean that if an element of v3 matches an element of v1 at
position i, then you want to know the ith element of v2. If that's
correct, then you can use something like:

Part[v2, Flatten[Position[v1,#]& /@ v3]]

or if you could probably use the Pick function if you're using version
5.1 or higher.  Perhaps something like the following could work:

Pick[v2,MemberQ[v3,#]&/@v1]

Note that this second method is untested here.

> Ex:
> v1={1,2,3,4,5,6,7,8,9}
> v2={10,11,12,22,32,42,53,63,73}
> v3={3,5,8}
> The corresponding v2 values are {11,32,63}

Are you sure?  My reading of what you're trying to do gives a result
of {12,32,63}.




  • Prev by Date: Re: Can anybody help?
  • Next by Date: Plotting an equation
  • Previous by thread: Re: Can anybody help?
  • Next by thread: Re: Can anybody help?