Find unique or duplicate cells in cell array of chars

35 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Data Types 的更多信息

产品


版本

R2016b

Community Treasure Hunt

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

Start Hunting!

Translated by