Deleting non-unique rows from an array

◇◆丶佛笑我妖孽 提交于 2019-12-06 03:26:34

The third output of unique gives you the index of the unique row in the original array. You can use this with accumarray to count the number of occurrences, which can be used to select rows that occur only once.

For example:

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

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

C = uniquerow(noccurrences==1, :);

Which returns:

>> C

C =

     3     4
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!