필터 지우기
필터 지우기

using the find function to find intersection of two lines

조회 수: 1 (최근 30일)
shobhit mehrotra
shobhit mehrotra 2015년 4월 15일
댓글: Renato Agurto 2015년 4월 16일
Hi,
I have a vector A :
A = [ 10 20 30 40 50 60 50 40 30 20 10]
I want to find the nearest index where it crosses 18, so in this case it would be 2 and 10.
AA = find(A=18)
Thanks!
  댓글 수: 2
Renato Agurto
Renato Agurto 2015년 4월 15일
Do you want to find the index for every time it crosses 18:
for example if
A = [10 20 30 40 50 60 50 40 30 21 10]
the answer would still be 2 and 10... or just 2?
shobhit mehrotra
shobhit mehrotra 2015년 4월 16일
Yes every time it crosses 18 so the answer would be 2 & 10

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

채택된 답변

Titus Edelhofer
Titus Edelhofer 2015년 4월 15일
Hi,
you are looking for sign changes of A-18:
find((A(2:end)-18).*(A(1:end-1)-18) < 0)
Hope this helps,
Titus
  댓글 수: 1
Renato Agurto
Renato Agurto 2015년 4월 16일
I just want to complement the answer, so the right index is shown if is nearer as the left:
tmp = find((A(2:end)-18).*(A(1:end-1)-18) < 0)
B = tmp + (abs(A(tmp) - 18) > abs(A(tmp+1)-18))

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

추가 답변 (1개)

Adam
Adam 2015년 4월 15일
find( A == 18 + min( abs( A - 18 ) ) )
is a one-liner to do what you want. Personally I would probably do it as multiple lines, but the idea is the same.
  댓글 수: 1
Titus Edelhofer
Titus Edelhofer 2015년 4월 15일
That's better than mine, because my code always selects the point to the left, Adam's picks the one that's nearer ...

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

카테고리

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

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by