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 16:23:50 -0500
Date: Wed, 13 Aug 2008 15:24:19 -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> <q8-dnUAG6IN0rD7VnZ2dnUVZ_rXinZ2d@forethought.net> <g7vejq$9ec$1@fred.mathworks.com>
In-Reply-To: <g7vejq$9ec$1@fred.mathworks.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <yvydnaqDMbl7zT7VnZ2dnUVZ_q7inZ2d@forethought.net>
Lines: 52
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-8lut0f4RwKJg1PVIzjgNPhzVWzFEu71esPJbaSoKBFZudHp3b/6LHl6GOd5Qr1HO+Ub9lWkDthdX9D5!StPGU65+Bs+p7lRayPOqTXCLv1Pa1PSzSHmvKlf2tE6a5UWHM8W6jo+TTio2Ag1+APxi03A8quT8!e5SF8ui7QUP5AXO+81lM+rc8
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: 2354
Xref: news.mathworks.com comp.soft-sys.matlab:485360



Ilya Rozenfeld wrote:
> It looks like using "strmatch" would be even easier:
> 
> data =ones(5, 6);
> data(3,:) =12;
> 
> x = ones(1,6)*12;
> strmatch(x, data)


It's a matter of performance.  strfind is by far the fastest of the methods.

Dan






> 
> 
> Dan Hensley <somewhere@over.there> wrote in message <q8-
> dnUAG6IN0rD7VnZ2dnUVZ_rXinZ2d@forethought.net>...
>> 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
>