Using the find function to pick out data when it crosses a limit

조회 수: 16 (최근 30일)
shobhit mehrotra
shobhit mehrotra 2015년 6월 22일
댓글: Guillaume 2015년 6월 22일
I have a vector
A= [12 34 56 78 94 104 160 199 233 277 287 300 302 309 345 4 26 45 66 77 89 123 234 280 321 344 6 13 ...]
where A, is in degrees. Everytime the value crosses 240, I want to find the index number right before the cross, so in this case [9 23]
find(AA crosses zero)
Thanks!

답변 (1개)

Guillaume
Guillaume 2015년 6월 22일
find( AA(1:end-1) < 240 & AA(2:end) > 240)
Note that if you're going to use the values returned by find to index an array, then you can dispense with the find and just use the logical array within the find for indexing.
  댓글 수: 2
shobhit mehrotra
shobhit mehrotra 2015년 6월 22일
It doesnt work, it only selected the indices when it crosses zero, not 240. Please help Thanks
Guillaume
Guillaume 2015년 6월 22일
Other than the mispelling in the variable name ( AA instead of A), the above does work exactly as you asked.
It finds the position of elements in AA which are strictly smaller than 240 AND for which the next element is greater than 240.
>>A = [12 34 56 78 94 104 160 199 233 277 287 300 302 309 345 4 26 45 66 77 89 123 234 280 321 344 6 13];
>>find( A(1:end-1) < 240 & A(2:end) > 240)
ans =
9 23

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

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by