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

5 ビュー (過去 30 日間)
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?

採用された回答

Walter Roberson
Walter Roberson 2021 年 3 月 13 日
[~, 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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by