Re: Try again, how to interleave two lists?
- To: mathgroup at smc.vnet.net
- Subject: [mg9510] Re: Try again, how to interleave two lists?
- From: Eckhard Hennig <hennig at itwm.uni-kl.de>
- Date: Sat, 8 Nov 1997 23:04:39 -0500
- Organization: ITWM
- Sender: owner-wri-mathgroup at wolfram.com
rob peterson wrote:
> I have two lists of 3D points which in ColumnForm, list A looks like::
> (In ColumnForm)
>
> {Ax1,Ay1,Az1}
> {Ax2,Ay2,Az2}
> .
> .
> {Axn,Ayn,Azn}
>
> B looks the same but with B entries.
>
> What I need is a list which looks like
>
> {
> {{Ax1,Ay1,Az1},{Bx1,By1,Bz1},{Ax2,Ay2,Az2},{Bx2,By2,Bz2}....{Bxn,Byn,Bzn}
> }
>
> Any suggestions on how to form this from the two A, B lists?
Dear Rob,
try this:
In[1]:= Interleave[listA_List, listB_List] :=
Flatten[Thread[{listA, listB}], 1]
In[2]:= a = {{Ax1,Ay1,Az1}, {Ax2,Ay2,Az2}, {Ax3,Ay3,Az3}};
In[3]:= b = {{Bx1,By1,Bz1}, {Bx2,By2,Bz2}, {Bx3,By3,Bz3}};
In[4]:= Interleave[a, b]
Out[4]= {{Ax1, Ay1, Az1}, {Bx1, By1, Bz1}, {Ax2, Ay2, Az2},
{Bx2, By2, Bz2}, {Ax3, Ay3, Az3}, {Bx3, By3, Bz3}}
-- Eckhard
----------------------------------------------------------------------------
Dipl.-Ing. Eckhard Hennig
mailto:hennig at itwm.uni-kl.de
Institut fuer Techno- und Wirtschaftsmathematik e.V. (ITWM)
Erwin-Schroedinger-Strasse, 67663 Kaiserslautern, Germany
Voice: +49-(0)631-205-3126 Fax: +49-(0)631-205-4139
http://www.e-technik.uni-kl.de/organizations/itwm/people/Hennig/Eckhard.html
----------------------------------------------------------------------------