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

3 visualizaciones (últimos 30 días)
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?

Respuesta aceptada

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

Más respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by