Re: Getting coordinates of array member

• To: mathgroup at smc.vnet.net
• Subject: [mg26285] Re: [mg26247] Getting coordinates of array member
• From: Tomas Garza <tgarza01 at prodigy.net.mx>
• Date: Sun, 10 Dec 2000 00:19:56 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```I guess the following will do the job (incidentally, to me (x, y) means
"row x, column y", while you have it the other way around):

In[1]:=
getPos[x_, y_, m_] := m[[x, y]]

In[2]:=
coord[x_, m_] :=
Module[{s = Dimensions[m][[2]], t},
t = Mod[x, s]; {Quotient[x, s] + If[t == 0, 0, 1], If[t ==
0, s, t]}]

Example:

In[3]:=
m = Partition[Range[1, 15], 3]
Out[3]=
{{1, 2, 3}, {4, 5, 6}, {7, 8, 9}, {10, 11, 12}, {13, 14, 15}}

In[4]:=
getPos[3, 2, m]
Out[4]=
8

In[5]:=
coord[8, m]
Out[5]=
{3, 2}

Tomas Garza
Mexico City

"Stephane Hebert" <stephhebert at yourpants~videotron.ca> wrote:

> Hi folks,
>
> Ok, let's say I have this
>
>      1  2  3
>     -----------
>  1| 1  2  3
>  2| 4  5  6
>  3| 7  8  9
>
> A 3x3 matrice or array.  Each number in the array represents its'
position
> from top left to bottom right.
>
> What I need to do is:
>
> Find what position 1,3 is.  Just by looking at the array, we find that
7 is
>
> Find what are the coordinates of 7.  Again just by looking at the
array we
> see that the answer is 1,3
>
> I need to come up with a simplu function that will return these.
>
> pos = GetPos(x,y)
>
> coord = GetCoord(pos)
>
> I've done this before, way long ago and can't find it.

```

• Prev by Date: Re: Big trouble with Mathematica Code parsing -- Rant.
• Next by Date: What makes things Listable?
• Previous by thread: Re: Getting coordinates of array member
• Next by thread: Re: Getting coordinates of array member