MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

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}}


  • Prev by Date: Re: axes for Plot3D
  • Next by Date: ImplicitPlot in 3D of several equations
  • Previous by thread: Re: How to "search" in a matrix?
  • Next by thread: Re: How to "search" in a matrix?