Effacer les filtres
Effacer les filtres

how can I remove similar numbers that FOLLOW ?

2 vues (au cours des 30 derniers jours)
MichMichel
MichMichel le 26 Fév 2013
Hello everybody,
I need your help about a small problem : I try to remove repetitions of a vector (only repetitions that follow!). There is a lot of help on the web in relation to this kind of problem, especially with the unique function but unfortunately it does not respond to my request.
I explain:
I have for example a vector x = [2 2 2 1 1 4 4 4 4 4 3 3 3 3 2 2 2 2 1 1 2 1 1 1] I want to get: y = [2 1 4 3 2 1 2 1] and not y = [2 1 4 3] as the unique function gives me (sorted or not). I want to remove only the repetitions that are follow and not all the duplicates ...
Do you have an idea without necessarily a function?
Thank you very much for your help,
DK

Réponses (3)

Miroslav Balda
Miroslav Balda le 26 Fév 2013
This code works:
y=x([x(2:end),0]~=x(1:end));

MichMichel
MichMichel le 26 Fév 2013
thanks a lot ;)

MichMichel
MichMichel le 26 Fév 2013
it's not work but i found that :
rep=diff(find(diff([-Inf x Inf])));
val=x(cumsum(rep));

Catégories

En savoir plus sur Shifting and Sorting Matrices 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