Matlab unique rows cell array / table 将不同的排列视为相等

Matlab unique rows cell array / table considering different permutations as equal

给定一个包含两列的元胞数组(或 table),如何找到行中值的唯一排列?即给定A = {'a','b';'b','a';'c','d'},应该返回的是{'a','b';'c','d'}.

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