从数组中删除重复的连续元素 [英] Remove repeating consecutive elements from array
本文介绍了从数组中删除重复的连续元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要一些有关MATLAB中数组的帮助:
试想像这样的数组
I need some help with arrays in MATLAB:
Imagine have an array like this
a = [1,1,1,1,2,2,4,4,4,7,7,7,1,1,1,1]
to并且喜欢获得此数组:
to and like to get this array:
b = [1,2,4,7,1]
我该怎么做?
推荐答案
只需使用其 diff
权限:
b = a( [true logical( diff(a(:)).') ] )
b =
1 2 4 7 1
这篇关于从数组中删除重复的连续元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文