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:
Intersection of index lists

Subject: Intersection of index lists

From: Johannes Korsawe

Date: 22 Aug, 2007 08:00:49

Message: 1 of 2

Hi out there,

i am looking for a loop-free solution for the following
problem:

Let a=[1,5,20,3,18,2];b=[5,5,5,6,6,6,2,2,2]; (index
vectors, i.e. positive integer values)

I am looking for ind=[1,2,3,7,8,9];

ind is an index into b giving the places of all values
insinde b which are also contained in a.

If i apply intersect, i only get ind=[3,9], which is the
largest index value into b where values of a are hit.

Thank you all in advance!

Best regards,
Johannes Korsawe

Subject: Intersection of index lists

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 22 Aug, 2007 09:43:23

Message: 2 of 2

In article <fagqfh$eec$1@fred.mathworks.com>,
Johannes Korsawe <johannes.korsawe.nospam@mathworks.com> wrote:
>Let a=[1,5,20,3,18,2];b=[5,5,5,6,6,6,2,2,2]; (index
>vectors, i.e. positive integer values)

>I am looking for ind=[1,2,3,7,8,9];

>ind is an index into b giving the places of all values
>insinde b which are also contained in a.

>> find(ismember(b,a))

ans =

     1 2 3 7 8 9

--
  "law -- it's a commodity"
                         -- Andrew Ryan (The Globe and Mail, 2005/11/26)

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