フィルターのクリア

Consecutive series of numbers

1 回表示 (過去 30 日間)
Meriem Deli
Meriem Deli 2017 年 1 月 27 日
回答済み: Jan 2017 年 1 月 27 日
Hello everyone,
I need some help, assume that I have a vector Days=[1 25 26 38 100 101 102 150 151 152 153 154 180 204 365] and I have to find the sequence of consecutive numbers (Duration), for exemple (25 26) , (100 101 102),(150 151 152 153 154), I tried with a for loop but I stuck on it.
Hope my question is clear, Thanks in advance
  2 件のコメント
Ganesh Hegade
Ganesh Hegade 2017 年 1 月 27 日
Jan
Jan 2017 年 1 月 27 日
Please post your code and explain, what does not work as expected. What is the wanted output?

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

回答 (1 件)

Jan
Jan 2017 年 1 月 27 日
Days = [1 25 26 38 100 101 102 150 151 152 153 154 180 204 365];
[B, N, Idx] = RunLength(diff(days));
Consecutive = (B == 1);
Start = Idx(Consecutive);
len = N(Consecutive);
Now Start and Len contain the limits of the intervals.

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by