How to remove consecutive duplicates ?

39 vues (au cours des 30 derniers jours)
Saravana priya
Saravana priya le 16 Juil 2018
for ex, step1=[{1}, {7,8}, {2}, {2}, {5}} I want my output to be step2=[{1}, {7,8}, {2}, {5}] Can anyone help me?

Réponses (1)

Pawel Jastrzebski
Pawel Jastrzebski le 16 Juil 2018
Consider the following example:
ConsecDuplic = [1 2 2 3 4 5 5 5 6 7 8 9 9]
% Logical vector:
% check if next value is the same as previous one
LV = [false ConsecDuplic(2:end) == ConsecDuplic(1:end-1)]
NoDuplic = ConsecDuplic(~LV)
  1 commentaire
Govind Narayan Sahu
Govind Narayan Sahu le 4 Oct 2022
Thanks it worked. Easy to implement...

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by