To delete duplicate rows in a matrix in Matlab, you can use the 'unique' function.
Here is the code to remove duplicate rows:
main.m170 chars7 lines
In this code, A
is your matrix. When passed to unique
with the option 'rows'
, it returns a matrix containing the distinct rows of A
. The second output idx
is an index vector that tells you where each of these distinct rows first appear in the original matrix. So the last line returns only the unique rows of the original matrix A
.
Note that the 'stable'
option is used to maintain the order of rows. If you don't care about the order of rows in the result, you can omit this parameter.
gistlibby LogSnag