フィルターのクリア

finding values common to 3 different single-column matrices

29 ビュー (過去 30 日間)
Michael
Michael 2011 年 5 月 19 日
コメント済み: Sibel Akyuz 2022 年 11 月 1 日
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
Andrei Bobrov 2011 年 5 月 19 日
intersect(intersect(A,B),C)
  2 件のコメント
Sean de Wolski
Sean de Wolski 2011 年 5 月 19 日
Golf:
m=@intersect;
m(C,m(A,B))
Sibel Akyuz
Sibel Akyuz 2022 年 11 月 1 日
very helpful thanks.

サインインしてコメントする。


Oleg Komarov
Oleg Komarov 2011 年 5 月 19 日
Out = intersectm(A,B,C)

Sean de Wolski
Sean de Wolski 2011 年 5 月 19 日
C(ismember(C,A(ismember(A,B))))
  1 件のコメント
Matt Fig
Matt Fig 2011 年 5 月 19 日
This approach can return repeated values if the elements of the individual vectors aren't unique.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeStructures についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by