필터 지우기
필터 지우기

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
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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by