How can I find elements in sequence in an array?

23 ビュー (過去 30 日間)
ishita agrawal
ishita agrawal 2017 年 5 月 23 日
コメント済み: ishita agrawal 2017 年 5 月 24 日
I have an array of numbers. I want to find set of numbers for which difference of two consecutive numbers is 1. For example, I have a sequence [2,3,6,8,9,10,12,14,16,17]. How can I extract position of (2,3), (8,9,10), (16,17)? I also want to save the output in a new array.

採用された回答

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,[0 1])
ii2=strfind(id,[ 1 0])
  3 件のコメント
Jan
Jan 2017 年 5 月 23 日
To avoid a collision with the elements on the margins:
id = [false, diff(v)==1, false];
ishita agrawal
ishita agrawal 2017 年 5 月 24 日
@Jan Simon Thank you for the suggestion.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMultidimensional Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by