Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Match matrix elements

Subject: Match matrix elements

From: Bobba Marco

Date: 20 Jan, 2009 12:09:03

Message: 1 of 6

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

Subject: Match matrix elements

From: Bruno Eklund

Date: 20 Jan, 2009 13:29:02

Message: 2 of 6

"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

Subject: Match matrix elements

From: Roger Stafford

Date: 20 Jan, 2009 15:50:18

Message: 3 of 6

"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

  I wouldn't be surprised if you are running out of memory, Marco. If you are using 'double' in A, it is filling up 43000000 x 5 x 8 = 1.72 gigabytes of contiguous memory. Creating room for 'RESULTS' will add substantially to this total. The 'ismember' function is the correct one to be using, but it also will need great quantities of memory to carry out its task in this case. You may be forced to work with smaller-sized matrices. The limitation is not matlab but the available resources on your computer.

Roger Stafford

Subject: Match matrix elements

From: Loren Shure

Date: 20 Jan, 2009 16:16:01

Message: 4 of 6

In article <gl4esv$t3e$1@fred.mathworks.com>, bobbaNO@mfn.SPAM.unipmn.it
says...
> 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
>
>

You inspired me to blog on this topic:
http://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-
data/

The short answer is:

FinalAnswer = ismember(A,B)

will get you the results you are looking for.


--
Loren
http://blogs.mathworks.com/loren

Subject: Match matrix elements

From: Jos

Date: 21 Jan, 2009 11:29:02

Message: 5 of 6

Loren Shure <loren@mathworks.com> wrote in message <MPG.23dfc2bb167363f998992c@news.mathworks.com>...
> In article <gl4esv$t3e$1@fred.mathworks.com>, bobbaNO@mfn.SPAM.unipmn.it
> says...
> > 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
> >
> >
>
> You inspired me to blog on this topic:
> http://blogs.mathworks.com/loren/2009/01/20/more-ways-to-find-matching-
> data/
>
> The short answer is:
>
> FinalAnswer = ismember(A,B)
>
> will get you the results you are looking for.
>
>
> --
> Loren
> http://blogs.mathworks.com/loren

Perhaps I have missed something but I assumed the problem was that the OP tried ISMEMBER but ran into memory issues?

Jos

Subject: Match matrix elements

From: us

Date: 21 Jan, 2009 14:27:02

Message: 6 of 6

Loren Shure

> > bobbaNO@mfn.SPAM.unipmn.it
> > 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.

> The short answer is:
> FinalAnswer = ismember(A,B)

that's exactly what the OP tried (the typical CSSM solution)... but he/she ran into memory problems...

us

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us