delete repeat data in matlab

To delete repeated rows from a matrix in MATLAB, you can use the unique function.

For example, let's say you have a matrix A:

main.m
A = [1, 2, 3; 
     4, 5, 6; 
     1, 2, 3; 
     7, 8, 9]
59 chars
5 lines

To delete the repeated rows, you can call unique on the matrix with the 'rows' option:

main.m
A = unique(A, 'rows')
22 chars
2 lines

This will return:

main.m
A =

     1     2     3
     4     5     6
     7     8     9
62 chars
6 lines

This will delete any rows that are exact duplicates of one another, leaving only one of each unique row remaining in the matrix.

related categories

gistlibby LogSnag