Borrar filtros
Borrar filtros

Finding series of repeating numbers in matrix

1 visualización (últimos 30 días)
Michael Saniuk
Michael Saniuk el 13 de Mayo de 2017
Comentada: Michael Saniuk el 13 de Mayo de 2017
Hello, I am trying to find begginings and endings of repeating zeros in matrix, eg: for input matrix:
1 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1
I want to get:
beggining = [2 9 14 21 25]
ending = [6 10 18 23 26]
Does anyone know how to do it?

Respuesta aceptada

Stephen23
Stephen23 el 13 de Mayo de 2017
Editada: Stephen23 el 13 de Mayo de 2017
>> V = [1,0,0,0,0,0,1,1,0,0,1,1,1,0,0,0,0,0,1,1,0,0,0,1,0,0,1];
>> D = [V(1)==0,diff(V==0)];
>> find(D>0)
ans =
2 9 14 21 25
>> find(D<0)-1
ans =
6 10 18 23 26

Más respuestas (1)

Guillaume
Guillaume el 13 de Mayo de 2017
v = [1 0 0 0 0 0 1 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1]
beginning = strfind([1 v], [1 0])
ending = strfind([v 1], [0 1])
Despite its name, strfind works with sequence of numbers as well.

Categorías

Más información sobre Characters and Strings 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