Re: Can anybody help?
- To: mathgroup at smc.vnet.net
- Subject: [mg63525] Re: [mg63519] Can anybody help?
- From: Adriano Pascoletti <pascolet at dimi.uniud.it>
- Date: Tue, 3 Jan 2006 05:24:41 -0500 (EST)
- References: <200601030626.BAA26066@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
In[1]:= v1={1,2,3,4,5,6,7,8,9}; v2={10,11,12,22,32,42,53,63,73};v3={3,5,8}; In[3]:= Flatten[Position[v1,#]]&/@v3 Out[3]= {{3},{5},{8}} In[4]:= Extract[v2,%] Out[4]= {12,32,63} Adriano Pascoletti Il giorno 3 gen 2006, alle ore 07:26, Kent Holing ha scritto: > 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. > 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} > It easy to write straightforward code to do this. > But is it really a very elegant/short way (one-liner?) of doing > this in Mathematica? > Kent Holing >
- References:
- Can anybody help?
- From: Kent Holing <KHO@statoil.com>
- Can anybody help?