Re: How to "search" in a matrix?

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

The following searches a 4x3 matrix for the symbol b, returning all the rows that contain it: In[52]:= Cases[{{a,b,1},{c,d,2},{e,f,3},{b,g,4}},x_/;MemberQ[x,b]:>x] Out[52]= {{a,b,1},{b,g,4}} Alternatively, one can use Select: In[54]:= Select[{{a,b,1},{c,d,2},{e,f,3},{b,g,4}},MemberQ[#,b]&] Out[54]= {{a,b,1},{b,g,4}}