Matlab独特的行单元阵列/表格考虑到不同的排列相等

时间:2017-07-18 08:05:07

标签: matlab cell-array

给定一个包含两列的单元格数组(或表),如何在行中查找值的唯一排列?也就是说,给定A = {'a','b';'b','a';'c','d'},应该返回的是{'a','b';'c','d'}

1 个答案:

答案 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