The function for determining the position of a given value in an array.

조회 수: 2 (최근 30일)
I have an array storing numerical values, I know the last part of this array are all zero values. How can I find the starting position of this part? In other words, I would like to find the starting position of 0 in this array. Which function should I use?

채택된 답변

Wayne King
Wayne King 2011년 11월 11일
x = ones(1e3,1);
x(750:end) = 0;
index = find(x == 0,1);
If you want to find the first K values.
K = 3;
indices = find(x==0,K,'first');
so
index = find(x == 0,1);
is equivalent to
index = find(x == 0,1,'first');

추가 답변 (0개)

카테고리

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