Filter löschen
Filter löschen

Finding series of repeating numbers in matrix

1 Ansicht (letzte 30 Tage)
Michael Saniuk
Michael Saniuk am 13 Mai 2017
Kommentiert: Michael Saniuk am 13 Mai 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?

Akzeptierte Antwort

Stephen23
Stephen23 am 13 Mai 2017
Bearbeitet: Stephen23 am 13 Mai 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

Weitere Antworten (1)

Guillaume
Guillaume am 13 Mai 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.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by