Re: Getting coordinates of array member
- To: mathgroup at smc.vnet.net
- Subject: [mg26292] Re: [mg26247] Getting coordinates of array member
- From: BobHanlon at aol.com
- Date: Sun, 10 Dec 2000 00:20:02 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
GetPos[{x_, y_}, mat_List] := mat[[y, x]];
GetCoord[value_, mat_List] := Reverse /@ Position[mat, value];
mat = Partition[Range[9], 3];
GetPos[{1, 3}, mat]
7
GetCoord[%, mat]
{{1, 3}}
This is a list of coordinates since, in general, there can be more than one
coordinate with the specified value. For example,
mat = IdentityMatrix[3];
GetCoord[1, mat]
{{1, 1}, {2, 2}, {3, 3}}
Bob Hanlon
In a message dated 12/6/00 3:08:08 AM, stephhebert at yourpants~videotron.ca
writes:
>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
>the answer.
>
>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)
>