フィルターのクリア

get the index of the n one in a binary vector

14 ビュー (過去 30 日間)
Luis Isaac
Luis Isaac 2019 年 1 月 21 日
回答済み: Stephen23 2019 年 1 月 21 日
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,

回答 (1 件)

Stephen23
Stephen23 2019 年 1 月 21 日
>> bv=[0,0,0,0,1,0,0,1,1,1,0,0,1,0,1];
>> idx = find(bv);
>> idx(4)
ans = 10

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by