using the find function to find intersection of two lines
显示 更早的评论
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
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
2015-4-16
采纳的回答
更多回答(1 个)
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
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 ...
类别
在 帮助中心 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!