Find unique or duplicate cells in cell array of chars

17 ビュー (過去 30 日間)
Hadi Zyien
Hadi Zyien 2019 年 8 月 29 日
回答済み: Jos (10584) 2019 年 8 月 29 日
If I have a cell array of cells containing strings such as:
A = {{'A', 'B', 'C'}, {'C', 'D', 'E'}, {'A', 'B', 'C'}, {'C', 'B', 'A'}}
how can I find which cells are duplicates of each other? Or conversely, how can I find which cells are unique?
In this example, the duplicate cells are A(1) and A(3), while the rest are unique.
Thanks!

採用された回答

Jos (10584)
Jos (10584) 2019 年 8 月 29 日
A = {{'A', 'B', 'C'}, {'C', 'D', 'E'}, {'A', 'B', 'C'}, {'C', 'B', 'A'}}
N = arrayfun(@(k) sum(arrayfun(@(j) isequal(A{k}, A{j}), 1:numel(A))), 1:numel(A))
unique_elements = A(N==1)
duplicated_elements = A(N>1)

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by