Re: Combining Lists
- To: mathgroup at smc.vnet.net
- Subject: [mg16780] Re: Combining Lists
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 24 Mar 1999 17:07:09 -0500
- References: <7d9rot$7pe@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
JOHN C ERB <JOHN_C_ERB at prodigy.net> wrote in message news:7d9rot$7pe at smc.vnet.net... > I have a set of x & y data points in one list; > > xydata={{x1,y1},{x2,y2},{x3,y3},{x4,y4}}; > > and a corresponding set of z data points in another list: > > zdata={z1,z2,z3,z4}; > > I wish to combine them into one list of {x,y,z} data points, > which I can do by: > > {temp1,temp2}=Transpose[xydata]; > xyzdata=Transpose[{temp1,temp2,zdata}] > > which gives the desired result: > > {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},{x4,y4,z4}} > > QUESTION: Is there a more efficient way of doing this? > > Thank you. > > John C. Erb > > email: John_C_Erb at prodigy.net > John, A variant on your method: xydata={{x1,y1},{x2,y2},{x3,y3},{x4,y4}}; zdata={z1,z2,z3,z4}; Flatten/@Transpose[{xydata, zdata}] {{x1,y1,z1},{x2,y2,z2},{x3,y3,z3},{x4,y4,z4}} Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565