MATLAB Answers

How to remove consecutive duplicates ?

51 views (last 30 days)
Saravana priya
Saravana priya on 16 Jul 2018
Answered: Pawel Jastrzebski on 16 Jul 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?

  0 Comments

Sign in to comment.

Answers (1)

Pawel Jastrzebski
Pawel Jastrzebski on 16 Jul 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)

  0 Comments

Sign in to comment.

Sign in to answer this question.

Tags


Translated by