You can use the unique function in MATLAB to identify the unique elements of a vector and the ismember function to determine which elements of the vector are duplicates. Here is an example code snippet:
main.m98 chars4 lines
In this code, unique(vec) returns [1 2 3 4 5], which corresponds to the unique elements of the original vector vec. The second line creates a logical vector is_duplicate indicating whether each element of vec is a duplicate (i.e., appears more than once) by comparing it against all but the first element of unique_vec.
Note that is_duplicate has the same size as vec and contains true for each duplicate element and false otherwise.
gistlibby LogSnag