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:
Using Intersect Without Removing Repetitions

Subject: Using Intersect Without Removing Repetitions

From: zcbtf89

Date: 10 Jan, 2013 11:14:09

Message: 1 of 3

I would like to do the following:

  [C ind] = intersect(A,B);

Where A(100,1), is a vector with a list of consecutive values from 1 to 1000 in a random order (i.e. value 3 is in row 11),
And B (5,1) is a vector with a shorter list of values all of which occur in A at some location. However there are some repetitions i.e. [1 3 5 5 70] ...

I would like my output vector 'ind' to account for these repetitions in B, such that the index in A repeats itself. i.e. for the above example ind = [ 1 11 25 25 100].

Any help regarding this would be much appreciated,

Thanks!

Subject: Using Intersect Without Removing Repetitions

From: Jos (10584)

Date: 10 Jan, 2013 13:01:09

Message: 2 of 3

"zcbtf89" wrote in message <kcm7q0$m1u$1@newscl01ah.mathworks.com>...
> I would like to do the following:
>
> [C ind] = intersect(A,B);
>
> Where A(100,1), is a vector with a list of consecutive values from 1 to 1000 in a random order (i.e. value 3 is in row 11),
> And B (5,1) is a vector with a shorter list of values all of which occur in A at some location. However there are some repetitions i.e. [1 3 5 5 70] ...
>
> I would like my output vector 'ind' to account for these repetitions in B, such that the index in A repeats itself. i.e. for the above example ind = [ 1 11 25 25 100].
>
> Any help regarding this would be much appreciated,
>
> Thanks!

I think ISMEMBER can do that for you

[tf,ind] = ismember(B,A)

~ Jos

Subject: Using Intersect Without Removing Repetitions

From: zcbtf89

Date: 10 Jan, 2013 13:21:09

Message: 3 of 3

you are absolutely right...

Tags for this Thread

No tags are associated with 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