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:
Quick INTERSECTION question

Subject: Quick INTERSECTION question

From: curoch

Date: 26 Jan, 2011 16:40:08

Message: 1 of 3

Hi all,

Previously, I have used a "for loop" using the "find" function to compare two matrices A (9444X1) (where there are several duplicates) and B(629X1) to return to me the row number (y) in a new matrix C where the element of a row in A is equal to the element in B.
A(n) == B(y) so C(n) = y

For instance, if A = [1 2 3 4 5 6 7 1 6]
                      B = [1 4 5 6]

Hence C = [1 0 0 2 3 4 0 1 4]

I have tried using ismember, intersections etc... but cannot find a way. Any suggestions ?

Thanks a lot in advance

Subject: Quick INTERSECTION question

From: Matt Fig

Date: 26 Jan, 2011 16:51:04

Message: 2 of 3

[C,C] = ismember(A,B);

Subject: Quick INTERSECTION question

From: curoch

Date: 26 Jan, 2011 17:04:03

Message: 3 of 3

"Matt Fig" wrote in message <ihpjdn$msp$1@fred.mathworks.com>...
> [C,C] = ismember(A,B);

Thanks a lot! Although I kinda feel like an idiot now...

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