Vectorized method to find the number of consecutive 1s from the left of an array
Mostra commenti meno recenti
Hi, I want to find the number of consecutive 1s from the left of an array (a binary array). For example, if I have A = [1 1 1 0 1 0 0 0 1 1] then the result would be 3 because there are 3 consecutive 1s from the left. Another example: A = [1 0 1 1 1 1 1] then the result would be 1. Or A = [0 1 1 1 0 0 1 0 1], the result would be 0.
I can write this in for loop, however I do not know how to vectorize this part. I really need it for my code so that it might run faster.
Please help me, thank you very much.
4 Commenti
Dang Manh Truong
il 27 Gen 2019
madhan ravi
il 27 Gen 2019
[Comment moved to answer section]
Dang Manh Truong
il 27 Gen 2019
madhan ravi
il 27 Gen 2019
See the edited answer below.
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Multidimensional Arrays 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!