从数组中删除非唯一行

fil*_*ili 3 matlab unique rows matrix duplicates

我有一个数组a如下:

a = [ 1 2; 3 4; 1 2 ];
Run Code Online (Sandbox Code Playgroud)

我想删除多次出现的所有行a并获取c:

c = [ 3 4 ];
Run Code Online (Sandbox Code Playgroud)

请注意,这与保留唯一行的操作不同,因为我不希望出现具有重复行的行.我怎么能做到这一点?

exc*_*aza 9

第三个输出unique为您提供原始数组中唯一行的索引.您可以使用它accumarray来计算出现次数,可用于选择仅出现一次的行.

例如:

A = [1 2; 3 4; 1 2];

[uniquerow, ~, rowidx] = unique(A, 'rows'); 
noccurrences = accumarray(rowidx, 1);

C = uniquerow(noccurrences==1, :);
Run Code Online (Sandbox Code Playgroud)

哪个回报:

>> C

C =

     3     4
Run Code Online (Sandbox Code Playgroud)