How to remove consecutive duplicates ?

38 visualizaciones (últimos 30 días)
Saravana priya
Saravana priya el 16 de Jul. de 2018
Comentada: Govind Narayan Sahu el 4 de Oct. de 2022
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?

Respuestas (1)

Pawel Jastrzebski
Pawel Jastrzebski el 16 de Jul. de 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)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by