Re: How to "search" in a matrix?

*To*: mathgroup at smc.vnet.net*Subject*: [mg60906] Re: How to "search" in a matrix?*From*: Peter Pein <petsie at dordos.net>*Date*: Mon, 3 Oct 2005 04:06:04 -0400 (EDT)*References*: <dhnt71$1hu$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Renan schrieb: > I have this matrix: > > matr = {{a, b, 1}, {c, d, 2}, {e, f, 3}} > > I'm trying to do a "search" in a matrix. The "real" matrix will contain strings. > How to "search" for a given value in a matrix and return all lines that have it? > > 'Select' seems to handle only lists - and this would require a > Flatten, probably making my code too complicated and maybe slow (the > real matrix will contain something like 100 elements - weather data). > > Thanks. > Hi Renan, a matrix _is_ a list (of lists): In[1]:= matr={{a,b,1},{c,d,2},{e,f,3}}; In[2]:= MemberRow[m_,el_]:=Select[m,MemberQ[#,el]&] In[3]:= MemberRow[matr,f] Out[3]= {{e,f,3}} In[4]:= MemberRow[Append[matr,{b,a,4}],b] Out[4]= {{a,b,1},{b,a,4}} Peter