Common numbers between arrays

2 ビュー (過去 30 日間)
Mo H
Mo H 2020 年 3 月 31 日
コメント済み: Mo H 2020 年 4 月 1 日
Hello,
I want to write a function that list out all common numbers between at least two array in a cell consisting of many arrays.
For instance, assume you have a cell array A = {[1,2,3], [3 4 5 6], [3 7 8 2], [11 3 15]}.
the result must be
A{1} = 2,3
A{2} = 3
A{3} = 3,2
A{4} = 3
Thank you a lot

採用された回答

James Tursa
James Tursa 2020 年 3 月 31 日
編集済み: James Tursa 2020 年 3 月 31 日
You could write some code using the intersect( ) function for this. E.g., the first result
>> A = {[1,2,3], [3 4 5 6], [3 7 8 2], [11 3 15]}
A =
1×4 cell array
{1×3 double} {1×4 double} {1×4 double} {1×3 double}
>> intersect(A{1},[A{2:4}])
ans =
2 3
You could write a loop where each cell is compared to a merging of the other cells as shown above.
  1 件のコメント
Mo H
Mo H 2020 年 4 月 1 日
I can't use intersect because I am doing some computation for each array element. The result will be compared to threshold to determine the relationship. Thank you for you effort.

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

その他の回答 (1 件)

KSSV
KSSV 2020 年 3 月 31 日
Read about intersection.

カテゴリ

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