Path: news.mathworks.com!not-for-mail
From: "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Find a vector in a matrix
Date: Wed, 13 Aug 2008 20:02:02 +0000 (UTC)
Organization: Citizens Bank
Lines: 41
Message-ID: <g7vejq$9ec$1@fred.mathworks.com>
References: <g7v6be$t4$1@fred.mathworks.com> <q8-dnUAG6IN0rD7VnZ2dnUVZ_rXinZ2d@forethought.net>
Reply-To: "Ilya Rozenfeld" <rozeni.nospam@alum.rpi.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1218657722 9676 172.30.248.38 (13 Aug 2008 20:02:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 13 Aug 2008 20:02:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 918333
Xref: news.mathworks.com comp.soft-sys.matlab:485345



It looks like using "strmatch" would be even easier:

data =ones(5, 6);
data(3,:) =12;

x = ones(1,6)*12;
strmatch(x, data)


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