Character Cell Array Comparison

1 回表示 (過去 30 日間)
Seb
Seb 2017 年 6 月 29 日
編集済み: Andrei Bobrov 2017 年 6 月 29 日
Ok, so excuse me; new to matlab and have not found a solution through google. I have a 3x2 cell array for example:
test = {'apple' 'banana'; 'banana' 'apple'; 'pear' '[]'}
And I want to compare the two columns (or however many there are) and return an array of all values that match. i.e return apple and banana from the test cell given. Essentially it just needs to discard any empty or unique values.
Any help much appreciated.

採用された回答

Andrei Bobrov
Andrei Bobrov 2017 年 6 月 29 日
編集済み: Andrei Bobrov 2017 年 6 月 29 日
[a,~,c] = unique(test);
out = a(accumarray(c,1)>1 & ~strcmp(a,'[]'));

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by