MathGroup Archive 2007

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

Search the Archive

Re: create a list with x,y,z coordinates

  • To: mathgroup at smc.vnet.net
  • Subject: [mg81571] Re: create a list with x,y,z coordinates
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Fri, 28 Sep 2007 02:07:45 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <fdf2ol$2i7$1@smc.vnet.net>

Claus wrote:

> I have a list of z-values:
> 
> zVals={13, 8, 15, 9, 15, 8, 11, 2, 18, 8, 5, 10, 11, 10, 9, 14, 6, 23, 
> 6, 14, 16, 5, 10, 5, 18, 10, 11, 10, 15, 8, 6, 23, 6, 17, 6, 12, 9, 17, 
> 4, 8, 18, 4, 18, 9, 13, 9, 14, 6, 10, 6, 5, 13, 5, 10, 6, 19, 8, 17, 9, 
> 16, 15, 5, 13, 5, 11, 9, 16, 2, 21, 11, 4, 15, 7, 10, 7, 16, 10, 14, 7, 
> 18, 17, 8, 15, 11, 14, 5, 14, 4, 13, 6, 8, 16, 8, 22, 8, 6, 9, 13, 5, 12}
> 
> These z-values are at grid points in a regularly spaced mesh, indices i 
> and j correspond to coordinates x and y, respectively. I can create the 
> mesh by
> 
> Table[{i,j},{i,0.05,1,0.1},{j,0.05,1,0.1}]
> 
> What is the best way in mathematica to "append" the z-values to the 
> (x,y)values?
> I know that they are in order corresponding to the (x,y)values; that is 
> 13 corresponds to (0.05,0.05) and 12 corresponds to (0.95,0.95).

One way of doing this is to use *Riffle* and *Partition* (the function 
called unflatten has been taken from the online help).

In[1]:= zVals = {13, 8, 15, 9, 15, 8, 11, 2, 18, 8, 5, 10, 11, 10, 9,
    14, 6, 23, 6, 14, 16, 5, 10, 5, 18, 10, 11, 10, 15, 8, 6, 23, 6,
    17, 6, 12, 9, 17, 4, 8, 18, 4, 18, 9, 13, 9, 14, 6, 10, 6, 5, 13,
    5, 10, 6, 19, 8, 17, 9, 16, 15, 5, 13, 5, 11, 9, 16, 2, 21, 11, 4,
    15, 7, 10, 7, 16, 10, 14, 7, 18, 17, 8, 15, 11, 14, 5, 14, 4, 13,
    6, 8, 16, 8, 22, 8, 6, 9, 13, 5, 12};
xyVals = Table[{i, j}, {i, 0.05, 1, 0.1}, {j, 0.05, 1, 0.1}];
unflatten[e_, {d__?((IntegerQ[#] && Positive[#]) &)}] :=
  Fold[Partition, e,
    Take[{d}, {-1, 2, -1}]] /; (Length[e] === Times[d])
unflatten[Riffle[Flatten@xyVals, zVals, {3, -1, 3}], {10, 10, 3}]

Out[4]= {{{0.05, 0.05, 13}, {0.05, 0.15, 8}, {0.05, 0.25, 15}, {0.05,
    0.35, 9}, {0.05, 0.45, 15}, {0.05, 0.55, 8}, {0.05, 0.65,
    11}, {0.05, 0.75, 2}, {0.05, 0.85, 18}, {0.05, 0.95, 8}}, {{0.15,
    0.05, 5}, {0.15, 0.15, 10}, {0.15, 0.25, 11}, {0.15, 0.35,
    10}, {0.15, 0.45, 9}, {0.15, 0.55, 14}, {0.15, 0.65, 6}, {0.15,
    0.75, 23}, {0.15, 0.85, 6}, {0.15, 0.95, 14}}, {{0.25, 0.05,
    16}, {0.25, 0.15, 5}, {0.25, 0.25, 10}, {0.25, 0.35, 5}, {0.25,
    0.45, 18}, {0.25, 0.55, 10}, {0.25, 0.65, 11}, {0.25, 0.75,
    10}, {0.25, 0.85, 15}, {0.25, 0.95, 8}}, {{0.35, 0.05, 6}, {0.35,
    0.15, 23}, {0.35, 0.25, 6}, {0.35, 0.35, 17}, {0.35, 0.45,
    6}, {0.35, 0.55, 12}, {0.35, 0.65, 9}, {0.35, 0.75, 17}, {0.35,
    0.85, 4}, {0.35, 0.95, 8}}, {{0.45, 0.05, 18}, {0.45, 0.15,
    4}, {0.45, 0.25, 18}, {0.45, 0.35, 9}, {0.45, 0.45, 13}, {0.45,
    0.55, 9}, {0.45, 0.65, 14}, {0.45, 0.75, 6}, {0.45, 0.85,
    10}, {0.45, 0.95, 6}}, {{0.55, 0.05, 5}, {0.55, 0.15, 13}, {0.55,
    0.25, 5}, {0.55, 0.35, 10}, {0.55, 0.45, 6}, {0.55, 0.55,
    19}, {0.55, 0.65, 8}, {0.55, 0.75, 17}, {0.55, 0.85, 9}, {0.55,
    0.95, 16}}, {{0.65, 0.05, 15}, {0.65, 0.15, 5}, {0.65, 0.25,
    13}, {0.65, 0.35, 5}, {0.65, 0.45, 11}, {0.65, 0.55, 9}, {0.65,
    0.65, 16}, {0.65, 0.75, 2}, {0.65, 0.85, 21}, {0.65, 0.95,
    11}}, {{0.75, 0.05, 4}, {0.75, 0.15, 15}, {0.75, 0.25, 7}, {0.75,
    0.35, 10}, {0.75, 0.45, 7}, {0.75, 0.55, 16}, {0.75, 0.65,
    10}, {0.75, 0.75, 14}, {0.75, 0.85, 7}, {0.75, 0.95, 18}}, {{0.85,
    0.05, 17}, {0.85, 0.15, 8}, {0.85, 0.25, 15}, {0.85, 0.35,
    11}, {0.85, 0.45, 14}, {0.85, 0.55, 5}, {0.85, 0.65, 14}, {0.85,
    0.75, 4}, {0.85, 0.85, 13}, {0.85, 0.95, 6}}, {{0.95, 0.05,
    8}, {0.95, 0.15, 16}, {0.95, 0.25, 8}, {0.95, 0.35, 22}, {0.95,
    0.45, 8}, {0.95, 0.55, 6}, {0.95, 0.65, 9}, {0.95, 0.75,
    13}, {0.95, 0.85, 5}, {0.95, 0.95, 12}}}

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: create a list with x,y,z coordinates
  • Next by Date: Re: create a list with x,y,z coordinates
  • Previous by thread: Re: create a list with x,y,z coordinates
  • Next by thread: Re: create a list with x,y,z coordinates