How can I tell if a rectangular matrix has duplicate rows in MATLAB?

前端 未结 4 785
南笙
南笙 2020-12-20 12:48

I have an n-by-m rectangular matrix (n != m). What\'s the best way to find out if there are any duplicate rows in it in MATLAB? What\'s the best way to find the indices of t

4条回答
  •  悲哀的现实
    2020-12-20 13:01

    Say your matrix is M:

    [S,idx1] = sortrows(M);
    idx2 = find(all(diff(S,1) == 0,2));
    out = unique(idx1([idx2;idx2+1]));
    

    out will contain the duplicate row indices if any.

提交回复
热议问题