compare elements of cell array

13 ビュー (過去 30 日間)
lucksBi
lucksBi 2017 年 6 月 10 日
コメント済み: lucksBi 2017 年 6 月 10 日
hey
how can i compare elements of a cell array like this .e.g.
array={[1,1,1,2];[1,3,9,2];[2,5,9];[1,4,7];[3,9];[1,2,4,5,2,1,6]}
array2=[5;6]
it'll compare elements of 'array2' (5 & 6 row of 'array') with other rows in 'array'. and if its elements matches it will show in output. e.g. for 5th row, it'll show [0; 3,9 ; 9; 0; 0] (0 in case if nothing matches)
Thanks

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 10 日
f = @(x)cellfun(@(y)y(ismember(y,array{x})),array([1:x-1,x+1:end]),'un',0);
out = arrayfun(f,array2,'un',0);
out = cat(2,out{:});
out(cellfun(@isempty,out)) = {0}
  1 件のコメント
lucksBi
lucksBi 2017 年 6 月 10 日
This is so accurate. Thank you so much.

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by