Given a cell array (or table) with, say, two columns, how to find unique permutations of values in the rows? That is, given A = {'a','b';'b','a';'c','d'}
, what should be returned is {'a','b';'c','d'}
.
The fact that A
is a cell array complicates things. You can do it this way:
[~, ~, 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