How to remove consecutive duplicates ?

조회 수: 35 (최근 30일)
Saravana priya
Saravana priya 2018년 7월 16일
댓글: Govind Narayan Sahu 2022년 10월 4일
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?

답변 (1개)

Pawel Jastrzebski
Pawel Jastrzebski 2018년 7월 16일
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
Govind Narayan Sahu
Govind Narayan Sahu 2022년 10월 4일
Thanks it worked. Easy to implement...

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by