Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg60930] Re: How to "search" in a matrix?
  • From: albert <awnl at arcor.de>
  • Date: Tue, 4 Oct 2005 01:24:57 -0400 (EDT)
  • References: <dhnt71$1hu$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

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

I think Cases is even easier to use for this case. If you are searching in
Matrices only, this is probably the thing to use when looking for lines
containing d:
 
Cases[matr,{___,d,___}]

It should work just as well for strings instead of symbols. For more
complicated structures, there are additional Arguments for Select and Cases
which control the level where to look for matches...

albert


  • Prev by Date: partitioning a string
  • Next by Date: Partition(divid string to substring
  • Previous by thread: Re: How to "search" in a matrix?
  • Next by thread: Re:A programming puzzle