Effacer les filtres
Effacer les filtres

How can I delete repeated elements? (not unique!)

1 vue (au cours des 30 derniers jours)
Barbara
Barbara le 13 Août 2014
Commenté : Barbara le 13 Août 2014
Hi, I'd like to delete repeated elements, but keep it in this way:
Input = [2 2 3 3 4 2 2 5 3 3]
Output = [2 3 4 2 5 3]
With unique, some of these elements disappear. Does exist an other function?
Thx

Réponse acceptée

Iain
Iain le 13 Août 2014
output = [input(1) input(find(diff(input))+1)]
  1 commentaire
Barbara
Barbara le 13 Août 2014
thank you :) based on what you've sent it works with this one:
output = input(find(diff(input)))

Connectez-vous pour commenter.

Plus de réponses (2)

Joakim Magnusson
Joakim Magnusson le 13 Août 2014
I don't know such a function, but try this:
Output = Input;
0 = 1;
while i < size(Output,2)
if Output(i) == Output(i+1)
Output(i+1) = [];
else
i = i+1;
end
end

Andrei Bobrov
Andrei Bobrov le 13 Août 2014
Modifié(e) : Andrei Bobrov le 13 Août 2014
Output = Input([true,diff(Input)~=0])

Catégories

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