Re: How to "search" in a matrix?
- To: mathgroup at smc.vnet.net
- Subject: [mg60899] Re: [mg60892] How to "search" in a matrix?
- From: ggroup at sarj.ca
- Date: Mon, 3 Oct 2005 04:05:59 -0400 (EDT)
- References: <200510020554.BAA01427@smc.vnet.net>
- Reply-to: ggroup at sarj.ca
- Sender: owner-wri-mathgroup at wolfram.com
On Sunday, October 2, 2005 at 01:54 GMT -0400, Renan wrote: > 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). I don't follow. The following seems to work just fine: In[1]:= matr = {{a, b, 1}, {c, d, 2}, {e, f, 3}, {a, b, 4}}; In[2]:= Select[matr, MemberQ[#,a]&] Out[2]= {{a, b, 1}, {a, b, 4}} As for string manipulation, look under Programming->String Manipulation in the help browser.
- References:
- How to "search" in a matrix?
- From: Renan <renan.birck@gmail.com>
- How to "search" in a matrix?