Using the find function to pick out data when it crosses a limit
3 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(1 个)
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 个评论
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 Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!