How to remove duplicate rows from matrix

21,113

See http://www.mathworks.com/help/techdoc/ref/unique.html

b = unique(A, 'rows') returns the unique rows of A.

Share:
21,113
nosbor
Author by

nosbor

I am

Updated on May 29, 2020

Comments

  • nosbor
    nosbor almost 4 years

    I want to remove duplicate rows from a matrix. I read How can I remove duplicates in an array but keep the same order?, but this is not exactly what I want.

    The solution above removes duplicate values (cells) from matrix (and returns a vector), but I need to remove duplicate rows and return a matrix — the same matrix without duplicate rows.

    Example:

    a = [1,2; 3,4; 5,6; 1,2; 7,8]
    
    a =
         1     2
         3     4
         5     6
         1     2
         7     8
    
    %...
    
    ans =
         1     2
         3     4
         5     6
         7     8
    

    The order doesn't matter.

  • Will
    Will about 12 years
    Does anyone know the algorithm used to compute that function?
  • cyborg
    cyborg about 12 years