Effacer les filtres
Effacer les filtres

finding values common to 3 different single-column matrices

29 vues (au cours des 30 derniers jours)
Michael
Michael le 19 Mai 2011
Commenté : Sibel Akyuz le 1 Nov 2022
basically i have 3 different matrices (A, B, and C). Each one contains different numbers and is of a different length. However, there are numbers common to all 3 of them. I need to be able to create an output that lists all numbers that are common to all 3 matrices.
For example,
A = [2; 5; 7; 9; 13];
B = [5; 13; 17];
C = [1; 2; 3; 5; 10; 13; 15; 16];
Thus, the common numbers in this case are 5 and 13.
Any idea how to compare the three and find these values?

Réponses (3)

Andrei Bobrov
Andrei Bobrov le 19 Mai 2011
intersect(intersect(A,B),C)
  2 commentaires
Sean de Wolski
Sean de Wolski le 19 Mai 2011
Golf:
m=@intersect;
m(C,m(A,B))
Sibel Akyuz
Sibel Akyuz le 1 Nov 2022
very helpful thanks.

Connectez-vous pour commenter.


Oleg Komarov
Oleg Komarov le 19 Mai 2011
Out = intersectm(A,B,C)

Sean de Wolski
Sean de Wolski le 19 Mai 2011
C(ismember(C,A(ismember(A,B))))
  1 commentaire
Matt Fig
Matt Fig le 19 Mai 2011
This approach can return repeated values if the elements of the individual vectors aren't unique.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Structures dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by