필터 지우기
필터 지우기

Find first index that exceeds condition

조회 수: 3 (최근 30일)
Jonathan Cheong
Jonathan Cheong 2021년 2월 25일
댓글: Jonathan Cheong 2021년 2월 25일
To elaborate and ensuring my questions are specific, I have a dataset and their index:
[1,2,3,4,5,6,7,8,9]
[1,4,8,0,0,1,9,0,3]
Say I would like to find the index and value of the 1st value > 2 after value (8)
Which means my desired output would look like this:
[7]
[9]
Normally, I would have a table of starting indices, but this is just a random sample to keep it short.
How do I code this?
Thanks.

답변 (1개)

KALYAN ACHARJYA
KALYAN ACHARJYA 2021년 2월 25일
"I would like to find the index and value of the 1st value > 2 after value (8)"
Is this?
data=[1,4,8,0,0,1,9,0,3]
idx8=find(data==8)
idx=find(diff(data)<0)
result_idx=idx(idx>idx8(1))
Answer would be 7 only, can you verify again?
  댓글 수: 2
Jonathan Cheong
Jonathan Cheong 2021년 2월 25일
Hey Kalyan, thanks for the answer.
Although it technically produces the correct output, it's more like hard coded.
Is there a method to code so that it applies across an entire array consistently?
For example I have attached files: starting index (fdd2), data (rain2).
Same situation just in the format of an array.
Jonathan Cheong
Jonathan Cheong 2021년 2월 25일
The data won't be exactly 0 but it will be less than 2.
Hence the code should stop when the 1st value greater than 2 after the starting index is reached

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

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by