Interval where values are greater than treshold

Hi everyone
Logic = Data > Treshold
I now need to know what the intervals are where the treshold is exceeded
Logic = [1 1 1 0 0 0 1 1 0 1]
Desired_Output = [1 3;7 8;10 10]
So - from 1 to 3, from 7 to 8 aswell as 10
I can't think of a good way to do this.
Thank in advance

 채택된 답변

Stephen23
Stephen23 2019년 12월 10일

0 개 추천

>> B = find([true;diff(Logic(:))>0]);
>> E = find([diff(Logic(:))<0;true]);
>> M = [B,E]
M =
1 3
7 8
10 10

추가 답변 (1개)

Jeremy
Jeremy 2019년 12월 10일

0 개 추천

I believe you are looking for the find command.
find(Logic)

댓글 수: 3

find(Logic) = [1 2 3 7 8 10]
not exactly - I'm aware of find; there's one more step to get to what I put as my desired Output .. and there's the issue
You could use
diff
to determine adjacent numbers and drop the intermediate numbers appropriately
Thanks for participating :)
idx = find(Logic)
idx(end+1) = 0
idx(diff(idx) ~= 1)
would be the indices that mark the end of the interval - but what about the start ?

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

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

태그

질문:

2019년 12월 10일

댓글:

2019년 12월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by