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

33 次查看(过去 30 天)
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!

采纳的回答

Bruno Luong
Bruno Luong 2022-8-7
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{:});

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Data Type Conversion 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by