Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: quick search of a binary array within a binary matrix.
Date: Mon, 30 May 2011 22:38:02 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 45
Message-ID: <is168a$fk2$1@newscl01ah.mathworks.com>
References: <is0oum$e82$1@newscl01ah.mathworks.com> <1f65bbd9-a072-4c94-a008-074edf3d3699@w21g2000yqm.googlegroups.com> <is0uio$r70$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1306795082 16002 172.30.248.48 (30 May 2011 22:38:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 30 May 2011 22:38:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:729376

"Jon" wrote in message <is0oum$e82$1@newscl01ah.mathworks.com>...
> Dear all
> My question is:
> I have a binary matrix
> B = [1 0 0, 0 1 1, 0 0 1, 1 1 0];
> Besides, I have a binary vecor
> b = [1 0 1]
> Is there any efficient way to check if b is contained in B? is it an advantage to have only binary numbers? And the fact that I dont want to know the exact position but only if it is contained? can be done by indexing?
> 
> In the real case, b is made up by 3000 elements so indexing may not be possible.
> 
> Thank you very much in advance.

"Jon" wrote in message <is0uio$r70$1@newscl01ah.mathworks.com>...
> Thank you very much for your rapid response!
> 
> There is not any special function to do that? I mean, doing
> tmp=find(b*B'==sum(b));
> is usually faster, rigth?
> 
> Thank you again!
- - - - - - - - -
  It is not clear what you are asking where you write

B = [1 0 0, 0 1 1, 0 0 1, 1 1 0];

You called it a matrix but, as it stands, it is a 1 by 12 vector.  If this is really what you mean, then are you asking whether b = [1 0 1] is one of the ten vectors within B: [1 0 0], [0 0 0], [0 0 1], [0 1 1], [1 1 0], [1 0 0], [0 0 1], [0 1 1], [1 1 1], [1 1 0], or are you asking whether b is one of the four vectors [1 0 0], [0 1 1, [0 0 1], [1 1 0]?

  If the latter is what you mean, then turn B into an actual matrix:

B = [1 0 0; 0 1 1; 0 0 1; 1 1 0];

and use 'ismember' with the 'rows' option:

 t = any(ismember(b,B,'rows'));

  If it is the former meaning then you should use the 'hankel' function on the vector version of B before using 'ismember'.

  One thing is certain.  The code

tmp=find(b*B'==sum(b));

will not get the answer you seem to be asking for by an conceivable stretch of the imagination.

Roger Stafford