Borrar filtros
Borrar filtros

How find non zero

1 visualización (últimos 30 días)
So
So el 6 de Jun. de 2016
Comentada: So el 6 de Jun. de 2016
Hello,
For example I have a vector A = [ 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0]. And I do find(A,2)-2, so I have the 2 zeros before the first one. However, how can I get the 5 zeros before the first one ? If i do find(A,5)-5 I will get only the 4 zeros because there is only four one.
Thank you.

Respuesta aceptada

Stephen23
Stephen23 el 6 de Jun. de 2016
>> A = [ 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0];
>> fun = @(n)find(A,1)-(n:-1:1);
>> fun(2)
ans =
6 7
>> fun(5)
ans =
3 4 5 6 7
  1 comentario
So
So el 6 de Jun. de 2016
Thank you Stephen :)

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 6 de Jun. de 2016
strfind(A, [0 0 0 0 0 1])

Categorías

Más información sobre Descriptive Statistics en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by