Effacer les filtres
Effacer les filtres

get the index of the n one in a binary vector

14 vues (au cours des 30 derniers jours)
Luis Isaac
Luis Isaac le 21 Jan 2019
Dear,
I have binary vector like bv=[0,0,0,0,1,0,0,1,1,1,0,0,1,0,1...] and I would like to get the index in bv of the n "1"
For example the index of the 4th "1" in bv is 10.
I know that using while loops and two counters it possible but I asking for are vectorized (more Matlab) solution
Thanks in advance,

Réponses (1)

Stephen23
Stephen23 le 21 Jan 2019
>> bv=[0,0,0,0,1,0,0,1,1,1,0,0,1,0,1];
>> idx = find(bv);
>> idx(4)
ans = 10

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by