### Tags: 0andxresulting, arrayi, arrays, certain, differentiate, intersection, matlab, programming, thata

# differentiate between intersection of two arrays

On Programmer » Matlab

3,877 words with 3 Comments; publish: Sun, 18 May 2008 19:05:00 GMT; (20062.99, « »)

hello...

i have a certain problem .. there are 2 arrays such that

a= [1 0 2 3 1 2 0 0 2 3 1 0 2 1 0 2 3 3]

b=[ 2 1 3 0];

and

x=resulting array

i have to CHECK ALL ELEMENTS OF ARRAY 'a' and VERIFY THAT THEY ARE

THE SAME AS THOSE IN ARRAY 'b'.

then i hav to store these values in the

resulting array x such that an element once stored should not be

stored again

the point here is that the resulting array would have the same

structure (length and values ) as b.

i.e. x=[2 1 3 0]

order of elements in x can be different than that of b

for this i used "intersect" function

BUT

for these two other arrays

a=[0 1 2 4 5 3 2 1 0 2 8 9];

b=[ 0 1 2 3];

i-e all elements of 's'and 't' do not xactly match ...so the

resultant should give an error while performing above task of

verifying that elements of 'a'and 'b' are same.but using intersect

function i simply get 'b'in result.

also for arrays

a=[0 1 4 2 6 2 0 1]

b=[0 1 2 3];

i get x=[0 1 2];

which should also give an error...so intersect function is of no

use.....how can i now solve this problem?

kindly help me perform this task

*http://matlab.todaysummary.com/q_matlab_13233.html*

All Comments

Leave a comment...

- 3 Comments
- "sami" <samis555.matlab.todaysummary.com.hotmail.com> wrote in message
news:ef2db8e.-1.matlab.todaysummary.com.webx.raydaftYaTP...

> hello...

> i have a certain problem .. there are 2 arrays such that

> a= [1 0 2 3 1 2 0 0 2 3 1 0 2 1 0 2 3 3]

> b=[ 2 1 3 0];

> and

> x=resulting array

> i have to CHECK ALL ELEMENTS OF ARRAY 'a' and VERIFY THAT THEY ARE

> THE SAME AS THOSE IN ARRAY 'b'.

> then i hav to store these values in the

> resulting array x such that an element once stored should not be

> stored again

> the point here is that the resulting array would have the same

> structure (length and values ) as b.

> i.e. x=[2 1 3 0]

> order of elements in x can be different than that of b

> for this i used "intersect" function

> BUT

> for these two other arrays

> a=[0 1 2 4 5 3 2 1 0 2 8 9];

> b=[ 0 1 2 3];

> i-e all elements of 's'and 't' do not xactly match ...so the

> resultant should give an error while performing above task of

> verifying that elements of 'a'and 'b' are same.but using intersect

> function i simply get 'b'in result.

> also for arrays

> a=[0 1 4 2 6 2 0 1]

> b=[0 1 2 3];

> i get x=[0 1 2];

> which should also give an error...so intersect function is of no

> use.....how can i now solve this problem?

> kindly help me perform this task

I don't really understand what you are trying to do. Could you describe it

again in words--the examples you give are not clear to me. Are you writing a

function? What are the inputs? What are the outputs? What do you want it to

do if the elements of b are not all present in a? etc.

#1; Sun, 18 May 2008 19:06:00 GMT

- "sami" <samis555.matlab.todaysummary.com.hotmail.com> wrote in message
- sami, have you even looked at the online help?
intersect provides the items of one vector in common with another

vector right?

that's the solution to 1/2 of your problem.

have you looked at the unique function?

do you wish someone to program the solution for you?

i won't do that, but i'll give you a further hint on how i would

approach the other 1/2 of your problem: i'd apply functions:

unique

union

size

alternatively i'd apply function: setxor

you're challenge (to yourself) is to find a third solution that doesn't

involve either of the above.

#2; Sun, 18 May 2008 19:07:00 GMT

- sami, have you even looked at the online help?
- hmm, i thought rabi asked the question initially. now sami is asking
the same thing. .

#3; Sun, 18 May 2008 19:08:00 GMT

- hmm, i thought rabi asked the question initially. now sami is asking