Remove duplicate rows based on subset of row elements

2 vues (au cours des 30 derniers jours)
Federico Maglione
Federico Maglione le 5 Mar 2019
Commenté : Vijay le 30 Sep 2020
Hello everyone,
I tried to find a similar problem - relatively simple I believe - but I could not find a solution. If, for instrance, I have a matrix such as
A = [1 1 1 100; 2 2 2 200; 3 3 3 300; 1 1 1 500]
how can I remove from A the fourth row based on the fact that only the thee first elements of the that row are identical to the three elmenets in the first row?
Also, what if I have
A = [1 1 1 100; 2 2 2 200; 3 3 3 300; 1 1 1 500; 1 1 1 600]
and, again, I just want to keep the first row?
Thank you for your help.

Réponse acceptée

madhan ravi
madhan ravi le 5 Mar 2019
Modifié(e) : madhan ravi le 5 Mar 2019
A(unique(A(1:3),'rows'),:)
  5 commentaires
Federico Maglione
Federico Maglione le 5 Mar 2019
Thank you! It works perfectly
Vijay
Vijay le 30 Sep 2020
Simple, but an excellent solution.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by