Hello
I have a 2xN matrix where each column represent the x and y coordinates of a 2D point. I need to remove any duplicate point from this matrix, any suggestions?
Best regards MC

댓글 수: 4

Stephen23
Stephen23 2017년 5월 14일
Note that 2xN is a matrix, and not a vector.
MC
MC 2017년 5월 14일
My bad, I meant a matrix:)
Garvit Amipara
Garvit Amipara 2022년 3월 6일
It would be very nice of you, if you could change the title of this question, it misleads others who are actually looking for the answers related to 'vector'. Thank you(:
Stephen23
Stephen23 2022년 3월 6일

댓글을 달려면 로그인하십시오.

 채택된 답변

Stephen23
Stephen23 2017년 5월 14일
편집: Stephen23 2017년 5월 14일

5 개 추천

It is trivial to use unique to get only the unique rows of matrix. Because your matrix is arranged 2xN, simply transpose before and after:
unique(M.','rows').'

댓글 수: 5

MC
MC 2017년 5월 14일
편집: MC 2017년 5월 14일
Thanks this worked almost! I manually checked the matrix, there is one part where there is 4 equal points, the command unique removes only two of them.
I just run it twice and it works fine!
Mr M.
Mr M. 2018년 2월 6일
what does it mean .' ? why not just ' is the transpose?
Guillaume
Guillaume 2018년 2월 6일
@Mr M, Why don't you look it up in the doc.
If your matrix is made of only non-complex number the difference does not matter, but if you may have complex numbers in your matrix, using ' instead of .' will lead to problems.
Stephen is correct to use .' in his answer.
LO
LO 2019년 4월 12일
how can I keep all values of each row ?
Paween Pongsomboon
Paween Pongsomboon 2022년 2월 18일
I don't know if you still alive, stephen. I wish I could hug you now!
Thx for the super solution

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

태그

질문:

MC
2017년 5월 14일

편집:

2022년 3월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by