Path: news.mathworks.com!newsfeed-00.mathworks.com!nlpi057.nbdc.sbc.com!prodigy.net!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local02.nntp.dca.giganews.com!nntp.forethought.net!news.forethought.net.POSTED!not-for-mail
NNTP-Posting-Date: Wed, 13 Aug 2008 14:11:37 -0500
Date: Wed, 13 Aug 2008 13:12:07 -0600
From: Dan Hensley <somewhere@over.there>
User-Agent: Thunderbird 2.0.0.16 (Windows/20080708)
MIME-Version: 1.0
Newsgroups: comp.soft-sys.matlab
Subject: Re: Find a vector in a matrix
References: <g7v6be$t4$1@fred.mathworks.com>
In-Reply-To: <g7v6be$t4$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <q8-dnUAG6IN0rD7VnZ2dnUVZ_rXinZ2d@forethought.net>
Lines: 28
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-dpqHI6Byp0glH0oTRv4CgyxUntERyg80Y/NPsSbWR5Ra17kX/B/HUsQelaJNl/yv6VFePP1B1sacSqx!2Rr8MGjXsxsWruOCimx3v/HRSKTIoxgJI+jPj4D4eY7Bx4UDoyNgHK4rvcTTb9U57q8JEA1Fjf6i!jJIK3wlSrL+N4slF6yJnKgeo
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.39
Bytes: 1814
Xref: news.mathworks.com comp.soft-sys.matlab:485332



Jonathan wrote:
> Is there an easy way to find a vector in a matrix?
> 
> for example
> 
>      1     1     1     1     1     1
>      1     1     1     1     1     1
>     12    12    12    12    12    12
>      1     1     1     1     1     1
>      1     1     1     1     1     1 
> 
> i want to identify the row that has [12 12 12 12 12 12]
> 
> Thanks

There's a strfind trick to do this.  It's very fast.

Assuming a is your matrix, and b is your vector,

 >> ind=strfind(reshape(a',1,[]),b)

Now if you're looking for a specific row, you need to make sure that the 
index corresponds to the start of a row:

ind = ind((ind-1)/size(a,2) == fix((ind-1)/size(a,2)))


Dan