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

3 Ansichten (letzte 30 Tage)
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?

Akzeptierte Antwort

Wayne King
Wayne King am 11 Nov. 2011
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');

Weitere Antworten (0)

Kategorien

Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by