Effacer les filtres
Effacer les filtres

unique values inside a matrix

2 vues (au cours des 30 derniers jours)
Michel tawil
Michel tawil le 21 Sep 2019
Commenté : Star Strider le 22 Sep 2019
Hello,
Assuming i have a matrix like this m=
1 30
1 20
1 20
1 20
2 30
2 28
2 28
... ...
i want it to be like this:
1 30
1 20
2 30
2 28
PS: THE MATRIX IS HUGE CONSISTING OF 11000 ROWS AND 9 COLUMNS
unique is not working since it has it's taking a unique value of all, for example if i apply it for the second column it will take 28 for 1 and not for 2
thank you in advance

Réponse acceptée

Star Strider
Star Strider le 21 Sep 2019
Modifié(e) : Star Strider le 21 Sep 2019
Try this:
A = [1 30
1 20
1 20
1 20
2 30
2 28
2 28];
Out = unique(A, 'rows', 'stable')
producing:
Out =
1 30
1 20
2 30
2 28
Experiment to get different results.
  9 commentaires
Michel tawil
Michel tawil le 22 Sep 2019
Modifié(e) : Michel tawil le 22 Sep 2019
Thank you!
Star Strider
Star Strider le 22 Sep 2019
As always, my pleasure!

Connectez-vous pour commenter.

Plus de réponses (1)

Guillaume
Guillaume le 21 Sep 2019
I'm not sure what you mean by unique is not working. You haven't explained the reasoning for going from your input to your output, but it does look like you want unique rows:
result = unique(m, 'rows')
With your demo data:
>> m = [
1 30
1 20
1 20
1 20
2 30
2 28
2 28];
>> unique(m, 'rows')
ans =
1 20
1 30
2 28
2 30
>> unique(m, 'rows', 'stable') %with stable to get the same order as your example
ans =
1 30
1 20
2 30
2 28
  5 commentaires
Michel tawil
Michel tawil le 21 Sep 2019
i can use this and it works well but i lose the cotents of the other colums
M=unique(C(:,1:2),'rows','stable');
Michel tawil
Michel tawil le 22 Sep 2019
Thank you !

Connectez-vous pour commenter.

Catégories

En savoir plus sur Tables 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