Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matlab compare different sized vectors

Tags:

matlab

If I have 2 vectors: A with n elements and B with m elements and m < n,

how do I identify all the elements in A which are in B, without using a for loop?

Many thanks

like image 593
E.D. Avatar asked Dec 06 '25 09:12

E.D.


1 Answers

C = intersect(A,B) will give you all the elements which are in both.

There's also ismember(A,B), which will return a logical array indicating for each member of A whether it is also a member of B.

like image 172
jam Avatar answered Dec 09 '25 00:12

jam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!