Re: Getting coordinates of array member
- To: mathgroup at smc.vnet.net
- Subject: [mg26265] Re: [mg26247] Getting coordinates of array member
- From: "Gareth J. Russell" <russell at cerc.columbia.edu>
- Date: Sun, 10 Dec 2000 00:19:38 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Stephane, you don't really need to define your own functions: Mathematica has them already. Note though, that it is conventional for matrix indices to indicate the row first, and then the column, so your example is incorrect. In[6]:= data = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Out[6]= {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}} In[7]:= data[[1, 3]] Out[7]= 3 In[8]:= Position[data, 7] Out[8]= {{3, 1}} on 12/6/00 2:16 AM, Stephane Hebert at stephhebert at yourpants~videotron.ca wrote: > 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) > > I've done this before, way long ago and can't find it. ================================================== Dr. Gareth J. Russell NEW ADDRESS and E-MAIL FROM 1ST SEPTEMBER, 1999 Center for Environmental Research and Conservation MC 5556 Columbia University 1200 Amsterdam Avenue New York, NY 10027, U.S.A. Phone: ++1 212 854 5094 Fax: ++1 212 854 8188 E-mail: russell at cerc.columbia.edu WWW: http://web.utk.edu/~grussell (NO CHANGE) OLD ADDRESS (AND STILL MY EMPLOYERS) Department of Ecology and Evolutionary Biology University of Tennessee 569 Dabney Hall Knoxville, TN 37996-1610, USA ==================================================