You can use the unique function in Matlab to get an array of unique values and the indices of the original array that correspond to these values. You can then use these indices to create a new array that contains only the unique values. Here's an example:
main.m108 chars4 lines
The resulting unique_array will be [1 2 3 4 5]. Note that we first used sort to put the values back in their original order, since unique sorts the values in ascending order by default.
Alternatively, you can also remove the repeated rows using the unique function directly by setting the 'rows' option.
main.m149 chars4 lines
The resulting unique_matrix will be:
main.m18 chars4 lines
Again the 'stable' option preserves the relative order of the rows.
gistlibby LogSnag