how to delete repeated data in matlab

To delete repeated data in Matlab, you can use the unique function as follows:

A = [1 2 2 3 4 4 4 5];
B = unique(A);
38 chars
3 lines

Output:

B = 
     1     2     3     4     5
36 chars
3 lines

This will remove all the repeated values in the array A and output the unique values in array B. You can also use the 'rows' parameter of the unique function to remove repeated rows of a matrix.

A = [1 2 3; 2 2 2; 1 2 3];
B = unique(A, 'rows');
50 chars
3 lines

Output:

B =
     1     2     3
     2     2     2
42 chars
4 lines

This will remove all the repeated rows in matrix A and output the unique rows in matrix B.

related categories

gistlibby LogSnag