How can I strip duplicates?

2 vues (au cours des 30 derniers jours)
Holm Roeser
Holm Roeser le 8 Avr 2021
Modifié(e) : per isakson le 13 Oct 2021
I wish to remove all duplicate rows based off of the first column. That is, I want to just strip the excess away. I am struggling to understand how to implement "unique" here. Thanks in advance
  5 commentaires
Cris LaPierre
Cris LaPierre le 9 Avr 2021
Ah, got it. Thanks.
per isakson
per isakson le 13 Oct 2021
Modifié(e) : per isakson le 13 Oct 2021
The values in the first column are not whole numbers. Thus uniquetol is appropriate.

Connectez-vous pour commenter.

Réponses (1)

Fangjun Jiang
Fangjun Jiang le 9 Avr 2021
If you want
  1. remove duplicates only based on values in the first column
  2. Do not want the returned values be sorted
then you need to do this
in=[[5;5;5;4;4;4;3;3;3;1],(1:10)'];
[~, index]=unique(in(:,1),'stable');
out=in(index,:)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by