Remove duplicate rows from matrix

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 个评论

Note that 2xN is a matrix, and not a vector.
My bad, I meant a matrix:)
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 2017-5-14
编辑:Stephen23 2017-5-14
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!
what does it mean .' ? why not just ' is the transpose?
@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.
how can I keep all values of each row ?
I don't know if you still alive, stephen. I wish I could hug you now!
Thx for the super solution

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Multidimensional Arrays 的更多信息

产品

标签

Community Treasure Hunt

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

Start Hunting!

Translated by