如何在数组中找到顺序的元素?

41次浏览(最近30天)
ishita agrawal
ishita agrawal 2017年5月23日
评论道: ishita agrawal2017年5月24日
我有一个数字数组。我想要找出一组数使两个连续数的差为1。例如,我有一个序列[2,3,6,8,9,10,12,14,16,17]。如何提取(2,3),(8,9,10),(16,17)的位置?我还想把输出保存在一个新的数组中。

0评论

登录并发表评论。

接受的答案

Azzi Abdelmalek
Azzi Abdelmalek 2017年5月23日
v =[2、3、6、8、9、10、12、14、16、17)
id = (10 diff (v) 10) = = 1
ii1 = strfind (id、1 [0])
ii2 = strfind (id、1 [0])

3评论

1月
1月 2017年5月23日
为了避免与边缘元素的冲突:
id = [false, diff(v)==1, false];
ishita agrawal
ishita agrawal 2017年5月24日
@Jan Simon谢谢你的建议。

登录并发表评论。

更多的答案(0)