finding values common to 3 different single-column matrices
显示 更早的评论
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?
回答(3 个)
Andrei Bobrov
2011-5-19
intersect(intersect(A,B),C)
2 个评论
Sean de Wolski
2011-5-19
Golf:
m=@intersect;
m(C,m(A,B))
Sibel Akyuz
2022-11-1
very helpful thanks.
Sean de Wolski
2011-5-19
C(ismember(C,A(ismember(A,B))))
1 个评论
Matt Fig
2011-5-19
This approach can return repeated values if the elements of the individual vectors aren't unique.
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!