How to remove the swap vectors from a matrix?

1 回表示 (過去 30 日間)
BALAKRISHNA ADHIKARI
BALAKRISHNA ADHIKARI 2020 年 10 月 5 日
Hello all,
I am facing few problem in MATLAB code and hoping to get solution from here. I am having a matrix of (30,2). As following
1 5
2 3
2 5
2 24
3 2
3 25
3 44
4 9
5 2
5 1
5 6
6 5
6 7
6 9
7 6
7 25
7 28
8 13
9 6
9 4
9 10
10 9
10 11
10 13
11 10
11 28
11 32
12 17
13 10
13 8
It can be seen that it has [2 3] in second row and [3 2] in fifth row andsimilarly few more rows are there. So, my problem is to remove the swaped row from the original and make another matrix. That means [2 3] will remain in the original matrix and [3 2] will goes to a new matrix. Similarly for other elements. Please help to get the code.
Best Regards

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 10 月 5 日
Try this
[~, idx] = unique(sort(M, 2), 'rows');
M_unique = M(idx, :);
  1 件のコメント
BALAKRISHNA ADHIKARI
BALAKRISHNA ADHIKARI 2020 年 10 月 5 日
Thanks Ameer. It did my work.

サインインしてコメントする。

その他の回答 (1 件)

madhan ravi
madhan ravi 2020 年 10 月 5 日
[Original_matrix, c, ~] = unique(sort(matrix, 2), 'rows');
New_matrix = matrix(setdiff(1:size(matrix, 1), c), :)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by