Re: Creating List
- To: mathgroup at smc.vnet.net
- Subject: [mg125535] Re: Creating List
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Sun, 18 Mar 2012 02:40:24 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
On 3/17/12 at 2:51 AM, hvdosten at gmail.com (Harry) wrote: >I have calculated some x- and y-values and want to combine them in a >way that the x and y-values define coordinates. Well, I have: >xkoor[i], {i, 1, iend} and ykoor[j], {j, 1, jend} >To be able to continue I need this list: >{{xkoor[1],ykoor[1]}, >{xkoor[2],ykoor[1]}, {xkoor[3],ykoor[1]}, {xkoor[4],ykoor[1]}, >{xkoor[1],ykoor[2]}, {xkoor[2],ykoor[2]}, {xkoor[3],ykoor[2]}, >{xkoor[4],ykoor[2]}, {xkoor[1],ykoor[3]}, {xkoor[2],ykoor[3]}, >{xkoor[3],ykoor[3]}, {xkoor[4],ykoor[3]}} >and have no idea how to get this. So I would be very happy to get >any small hint... Here is something to consider: In[13]:= x = Range[4]; y = Range[5, 15, 5]; In[15]:= Join @@ ((Join @@ Outer[List, x, {#}]) & /@ y) Out[15]= {{1, 5}, {2, 5}, {3, 5}, {4, 5}, {1, 10}, {2, 10}, {3, 10}, {4, 10}, {1, 15}, {2, 15}, {3, 15}, {4, 15}} But do note, this code creates a 2-D list, i.e., a list of lists not what you showed in your post. I can generate the output you posted with: In[18]:= Join @@ ((Join @@ Outer[{xkoor[#1], ykoor[#2]} &, Range[4], {#}]) & /@ Range[3]) Out[18]= {{xkoor[1], ykoor[1]}, {xkoor[2], ykoor[1]}, {xkoor[3], ykoor[1]}, {xkoor[4], ykoor[1]}, {xkoor[1], ykoor[2]}, {xkoor[2], ykoor[2]}, {xkoor[3], ykoor[2]}, {xkoor[4], ykoor[2]}, {xkoor[1], ykoor[3]}, {xkoor[2], ykoor[3]}, {xkoor[3], ykoor[3]}, {xkoor[4], ykoor[3]}}