Removing duplicates of rows from a matrix (finding and removing combination duplicates)
5 views (last 30 days)
Show older comments
I have a 12x3 double matrix and I want to identify duplicates of combinations of the same numbers and then produce a matrix containing the rows minus those duplicates (e.g. remove 2 as it is a duplicate of combo 1).

How can I go about this?
0 Comments
Accepted Answer
Walter Roberson
on 13 Mar 2021
[~, ia] = unique(sort(YourMatrix, 2),'rows', 'stable');
NewMatrix = YourMatrix(ia,:);
Although the sort() changes the order of the columns, I go back to the original for the indexing. So for example if the first row had been [5 3 4] then the first row of output would be [5 3 4]... just in case that was important to you.
More Answers (0)
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!