给定一个包含两列的单元格数组(或表),如何在行中查找值的唯一排列?也就是说,给定A = {'a','b';'b','a';'c','d'}
,应该返回的是{'a','b';'c','d'}
。
答案 0 :(得分:2)
A
是一个单元格数组的事实使事情复杂化。你可以这样做:
[~, ~, u] = unique(A); % get unique labels of cells
u = reshape(u,size(A)); % reshape into original shape
u = sort(u,2); % sort each row
[~, r] = unique(u, 'rows'); % indices of unique rows
result = A(r,:); % use those indices into input cell array