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

16 visualizzazioni (ultimi 30 giorni)
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!

Risposte (1)

Guillaume
Guillaume il 22 Giu 2015
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 Commenti
shobhit mehrotra
shobhit mehrotra il 22 Giu 2015
It doesnt work, it only selected the indices when it crosses zero, not 240. Please help Thanks
Guillaume
Guillaume il 22 Giu 2015
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

Accedi per commentare.

Categorie

Scopri di più su Operators and Elementary Operations in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by