필터 지우기
필터 지우기

how to find out the time interval between two consecutive events?

조회 수: 4 (최근 30일)
trailokya
trailokya 2014년 12월 13일
편집: Guillaume 2014년 12월 14일
sir, i need to find out the time interval between two consecutive events. i have around 4000 data with increasing numbers but not consecutive. i have to find out the events of 4 consecutive numbers or more and the gap between two consecutive events. how is it possible?
  댓글 수: 1
Guillaume
Guillaume 2014년 12월 14일
편집: Guillaume 2014년 12월 14일
I've turned this question into a cody problem.
So far, the best solution is more or less the same as mine below

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2014년 12월 13일
This would work:
A = [1,2,5,6,7,8,9,20,21,22,30,31,32,33, 34,35, 40,41,42,43,44];
runs = diff(A) == 1; %which numbers are part of a run
edges = diff([0 runs 0]); %find edges of run (1 = start, -1 = end)
startruns = find(edges == 1); %get indices of start of runs == indices in A
endruns = find(edges == -1); %get indices of end of runs == indices in A
lengthruns = endruns - startruns; %get lengths of runs
startruns = startruns(lengthruns >= 4); %only keep runs of 4 or more
endruns = endruns(lengthruns >= 4); %only keep runs of 4 or more
groupdiff = A(startruns(2:end)) - A(endruns(1:end-1))

추가 답변 (1개)

dpb
dpb 2014년 12월 13일
  댓글 수: 3
dpb
dpb 2014년 12월 13일
Did you not look at the linked-to File Exchange routines? I believe either of them will do the job for you...
Without extensive testing, I believe
>> d=find(diff([0 A])>1);
>> d(diff(d)>3)
ans =
3 11
>>
are the locations in question, but I suspect the two submittals are more robust.
trailokya
trailokya 2014년 12월 13일
the first group is 5,6,7,8,9 and the second one is 30,31,32,33,34,35 and the third one is 40,41,42,43,44 and the gap between the first and second is 21 and the second and third is 5. how it is 3 and 11?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Variables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by