MathGroup Archive 2012

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

Search the Archive

Re: Creating List

On 3/17/12 at 2:51 AM, hvdosten at (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[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],

  • Prev by Date: Re: Cool example with ContourPlot+EvaluationMonitor
  • Next by Date: Re: How to remove unwanted, garbage plotmarkers
  • Previous by thread: Re: Creating List
  • Next by thread: Running mathematica from terminal.