Path: news.mathworks.com!not-for-mail
From: "Bruno Eklund" <bruno.eklund@talktalk.net>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Match matrix elements
Date: Tue, 20 Jan 2009 13:29:02 +0000 (UTC)
Organization: Bank of England
Lines: 43
Message-ID: <gl4jiu$oml$1@fred.mathworks.com>
References: <gl4esv$t3e$1@fred.mathworks.com>
Reply-To: "Bruno Eklund" <bruno.eklund@talktalk.net>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1232458142 25301 172.30.248.35 (20 Jan 2009 13:29:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 20 Jan 2009 13:29:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1378704
Xref: news.mathworks.com comp.soft-sys.matlab:512694

"Bobba Marco" <bobbaNO@mfn.SPAM.unipmn.it> wrote in message <gl4esv$t3e$1@fred.mathworks.com>...
> Hi, I have two matrix A and B:
> 
> A = 43000000 x 5
> B = 1 x 5
> 
> I show an example to clarify the target:
> 
> A = [11 22 34 56 89             B = [11 66 44 40 90}
>        23 44 11 20 66
>        79 54 32 17 89
>        11 66 21 45 90
>         ... ... ... ... ...]
> 
> RESULTS = [1 0 0 0 0
>                   0 1 1 0 1
>                   0 0 0 0 0
>                   1 1 0 0 1
>                   .. .. .. .. ..]
> 
> I would like to build a matrix (RESULTS) in which appears 1 if an element of B is present in A and zero if not present.
> I used "ismember" function but the error HELP OF MEMORY appears.
> 
> Can you help me to solve problems in a short time?
> 
> Thanks
> 
> Marco

Hi Marco,
try this:

RESULTS = zeros(size(A));
for i = 1: size(B,2)
    RESULTS = RESULTS + ( A == B(1,i) );
end

That should work, even though you have to loop over all
the elements in B. Might be possible some more general 
matrix methods exist, but I havn't found any in my work.

Good luck,
Bruno Eklund