How to remove the swap vectors from a matrix?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
BALAKRISHNA ADHIKARI
el 5 de Oct. de 2020
Comentada: BALAKRISHNA ADHIKARI
el 5 de Oct. de 2020
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
0 comentarios
Respuesta aceptada
Ameer Hamza
el 5 de Oct. de 2020
Try this
[~, idx] = unique(sort(M, 2), 'rows');
M_unique = M(idx, :);
Más respuestas (1)
madhan ravi
el 5 de Oct. de 2020
[Original_matrix, c, ~] = unique(sort(matrix, 2), 'rows');
New_matrix = matrix(setdiff(1:size(matrix, 1), c), :)
Ver también
Categorías
Más información sobre Matrix Indexing en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!