How do I record the location of a specific value in a set of data?
Afficher commentaires plus anciens
Hello,
I am very new to matlab, and would appreciate advice!
I understand my question is not entirely clear. So I am trying to go through data that looks like:
[1] 0 0 0 0 1 0 1 0 0
And want the code to index until it encounters the first 1 (ignoring the rest of the 1s repeated in the row) then state the distance from the start of the row to the first 1 [so here it would be the distance from column 5 to column 1]
Then ideally it would repeat the same thing for a second row. My 'for' loop is not working, and ideally this code would work for dozens of rows of data. Thank you :)
Réponse acceptée
Plus de réponses (1)
Vladimir Sovkov
le 17 Juin 2020
a=[0 0 0 0 1 0 1 0 0];
k=find(a==1,1)
1 commentaire
Madison Castellanos
le 17 Juin 2020
Catégories
En savoir plus sur Matrix Indexing dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!