How do you find the index of the first true value in a logical vector?
Mostra commenti meno recenti
I need to find the index of the first 1 in a logical vector.
For example, I have a logical vector like this: V = [ 0 1 0 0 1 0 1 ] and I need a function/code that will tell me that the first true value is at index 2.
(If you can't tell from my question, I'm a beginner at Matlab.) Thanks so much for your help! I really appreciate it :)
Risposta accettata
Più risposte (1)
Guillaume
il 18 Set 2014
find(V, 1);
find doesn't care that your vector is logical, it'll find the non-zero values anyway.
3 Commenti
chandra Naik
il 26 Lug 2019
How to find first occurrence of any integer in an array
Velautham Daksiya
il 14 Ott 2021
V1=find(V==a,b,'first')
a- integer to be found
b-no of entries to be found
'first' or 'last' - from first or from last of v
Alexander
il 17 Lug 2022
Thank you
Categorie
Scopri di più su Matrix Indexing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!