Given a 2D matrix, I'd like to find the number of rows with unique sets of numbers. For example:
A = [1 4;
2 3;
3 2;
1 4];
The "unique sets" matrix return should be:
B = [1 4;
2 3];
and the indices of these should be
iA = [1 2];
Using unique(A,'rows') sees [2 3] and [3 2] as unique, but I want to consider them as non-unique.

 採用された回答

Matt J
Matt J 2022 年 8 月 4 日
編集済み: Matt J 2022 年 8 月 4 日

0 投票

A = [1 4;
2 3;
3 2;
1 4];
[B,iA]=unique(sort(A,2),'rows')
B = 2×2
1 4 2 3
iA = 2×1
1 2

その他の回答 (1 件)

Les Beckham
Les Beckham 2022 年 8 月 4 日
編集済み: Les Beckham 2022 年 8 月 4 日

0 投票

A = [1 4;
2 3;
3 2;
1 4];
B = unique(sort(A, 2), 'rows')
ans = 2×2
1 4 2 3

カテゴリ

ヘルプ センター および File ExchangeMathematics についてさらに検索

質問済み:

2022 年 8 月 4 日

編集済み:

2022 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by