How to remove consecutive duplicates ?
17 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
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)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!