フィルターのクリア

finding the common numbers in 2 arrays

20 ビュー (過去 30 日間)
Jonathan Bird
Jonathan Bird 2018 年 2 月 19 日
コメント済み: Jonathan Bird 2018 年 2 月 19 日
I want to compare two arrays each containing 6 numbers e.g. [1,2,3,4,5,6] and [4,8,6,10,11,12]. I want to determine how many numbers are common to both arrays (not necessarily in the same location) so the above would yield an answer of 2 as 4 and 6 are common to both. Thanks!

採用された回答

Jan
Jan 2018 年 2 月 19 日
See:
doc ismember
With code:
a = [1,2,3,4,5,6]
b = [4,8,6,10,11,12]
nCommon = sum(ismember(a, b))
Maybe the inputs are not unique, then apply unique() at first.
  1 件のコメント
Jonathan Bird
Jonathan Bird 2018 年 2 月 19 日
thanks

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by