Borrar filtros
Borrar filtros

Find a block of ones in a vector

2 visualizaciones (últimos 30 días)
fcarl
fcarl el 12 de Sept. de 2011
Hi,
I have a simple question but no matlab command for this :). I have a vector containing zeros and ones. I want to find every beginning of a block containing only of ones. For example: 000110011100. I want to get 4 and 8 as the indices indicating the beginning of a block with only ones.
Thank you for your efforts.

Respuesta aceptada

Fangjun Jiang
Fangjun Jiang el 12 de Sept. de 2011
a=[0 0 0 1 1 0 0 1 1 1 0 0]
ind=find(diff(a)==1)+1
Not too fast. This won't work if a starts with 1. Use this instead
a=[1 1 0 0 0 1 1 0 0 1 1 1 0 0]
ind=find(diff([0 a])==1)
  3 comentarios
Fangjun Jiang
Fangjun Jiang el 12 de Sept. de 2011
See my update.
Andrei Bobrov
Andrei Bobrov el 12 de Sept. de 2011
ind = strfind([0 a],[0 1])

Iniciar sesión para comentar.

Más respuestas (1)

fcarl
fcarl el 12 de Sept. de 2011
I recognized this ;) the function was helpfull :)

Categorías

Más información sobre Modeling 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