How to find the intersection of multiple arrays (or rows of a matrix) in a short code

90 views (last 30 days)
Hi MathWorks Community,
I have a problem with finding the intersection of multiple verctors.
First, I used the Intersect function in MATLAB. But it provide intersection of only two vector. It will be confusing when using it for multiple vectors.
Then, I found a fucntion called mintersect that in fact find multiple intersects and gives what is mutual between all arrays you have; but it cannot be quite helpful for me since, in my work with 172 vectors, when using mintersect, you need to write the name of all vectors as the input and the code become too long.
So when I am using mintersect it would be like:
mintersect(a , b , c , d , e , f , ...)
and I have 172 vectors! It is hard to write all of them in the code and seems like a not a smart job to do!
I thought if I give a matrix instead of vectors to mintersect, then it works. But unfortuantly it did not.
Would you please give me a solution to this matter in order to find intersection of let's say 172 vectors (or a matrix of the same size)?
Thanks!

Accepted Answer

Bruno Luong
Bruno Luong on 7 Aug 2022
Put in the cell then use comma list systax:
c = {a, b, c, ...}; % or use mat2cell, num2cell depends how you store your 172 vectors and you don't bother to tell how.
theintersect = mintersect(c{:});

More Answers (0)

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!