Find unique in matrix of x,y coordinates

27 vues (au cours des 30 derniers jours)
Ruchi Bhatia
Ruchi Bhatia le 19 Déc 2017
Commenté : Ruchi Bhatia le 20 Déc 2017
Hello, I would love your help.
If I have a matrix of x,y coordinates for example:
x y
A=[ 2.5 3.5
1.2 3.5
2.2 1.2
1.2 3.5
4.0 2.2 ]
How do I find a unique of this? In the above example one instance of x,y (1.2, 3.5) will be removed?

Réponse acceptée

Kelly Kearney
Kelly Kearney le 19 Déc 2017
To find unique rows, you can use unique with the 'rows' option. (The 'stable' option preserves the input order, if that's important for your application).
unique(A, 'rows', 'stable')
  1 commentaire
Ruchi Bhatia
Ruchi Bhatia le 19 Déc 2017
Thanks. Wow, didn't realize it was that straight forward.

Connectez-vous pour commenter.

Plus de réponses (2)

Image Analyst
Image Analyst le 19 Déc 2017
Try unique() with the 'rows' option:
uniqueRowsOfA = unique(A, 'rows')

Kaushik Lakshminarasimhan
Kaushik Lakshminarasimhan le 19 Déc 2017
Did you try this?
[C,IA] = unique(A,'rows');
C contains all unique rows of A. IA contains the indices of the rows of A that are in C. So if you want the indices of the rows that were removed, you can use:
[nrows,~] = size(A);
notIA = setdiff(1:nrows,IA); % duplicate rows
  1 commentaire
Ruchi Bhatia
Ruchi Bhatia le 19 Déc 2017
Thank you! Very helpful.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by