フィルターのクリア

Finding series of repeating numbers in matrix

1 回表示 (過去 30 日間)
Michael Saniuk
Michael Saniuk 2017 年 5 月 13 日
コメント済み: Michael Saniuk 2017 年 5 月 13 日
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?

採用された回答

Stephen23
Stephen23 2017 年 5 月 13 日
編集済み: Stephen23 2017 年 5 月 13 日
>> 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
  1 件のコメント
Michael Saniuk
Michael Saniuk 2017 年 5 月 13 日
thanks, it worked!

サインインしてコメントする。

その他の回答 (1 件)

Guillaume
Guillaume 2017 年 5 月 13 日
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.
  1 件のコメント
Michael Saniuk
Michael Saniuk 2017 年 5 月 13 日
wow, this works too ^^ thank you

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by