필터 지우기
필터 지우기

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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by