Removing duplicates of rows from a matrix (finding and removing combination duplicates)

5 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 13 Mär. 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.

Weitere Antworten (0)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by