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 19:19:07 +0000 (UTC) Organization: Norwegian University of Science and Technology Lines: 23 Message-ID: <is0qjb$i0e$1@newscl01ah.mathworks.com> References: <is0oum$e82$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 1306783147 18446 172.30.248.48 (30 May 2011 19:19:07 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Mon, 30 May 2011 19:19:07 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1555892 Xref: news.mathworks.com comp.soft-sys.matlab:729335 "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. Probably not the most compact solution, but works: B = [1 0 0; 0 1 1; 0 0 1; 1 1 0; 1 0 1]; b = [1 0 1]; [M N] = size(B); C = repmat(b,M,1) t = sum(~xor(B,C),2); if ~isempty(find(t==numel(b), 1)) isMem = 1 end