Filter löschen
Filter löschen

get the index of the n one in a binary vector

14 Ansichten (letzte 30 Tage)
Luis Isaac
Luis Isaac am 21 Jan. 2019
Beantwortet: Stephen23 am 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,

Antworten (1)

Stephen23
Stephen23 am 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

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by