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

90 visualizaciones (últimos 30 días)
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!

Respuesta aceptada

Bruno Luong
Bruno Luong el 7 de Ag. de 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{:});

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by