How to find the position of the first non-zero element of my matrix?

조회 수: 419 (최근 30일)
Leon
Leon 2020년 3월 10일
댓글: Leon 2020년 3월 10일
For example, if I have a column data like the below:
A = [0; 1; 0; 0; 0];
The answer would be 2.
For the below example:
B = [ 0; 0; 1; 0; 1; 0; 0];
The answer would be 3.
Is there a function to do that quickly?

채택된 답변

Stephen23
Stephen23 2020년 3월 10일
편집: Stephen23 2020년 3월 10일
find(yourVector,1,'first')

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by