Azzera filtri
Azzera filtri

Finding series of repeating numbers in matrix

1 visualizzazione (ultimi 30 giorni)
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?

Risposta accettata

Stephen23
Stephen23 il 13 Mag 2017
Modificato: Stephen23 il 13 Mag 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

Più risposte (1)

Guillaume
Guillaume il 13 Mag 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.

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by