Find pattern of ones

2 ビュー (過去 30 日間)
Renee
Renee 2014 年 4 月 26 日
コメント済み: Renee 2014 年 4 月 26 日
I have a matrix of ones and zeros for example: A=[ 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 ];
I need to find the number of patterns of [1 1 1 1] without overlapping. So, for example the matrix [1 1 1 1 1 1 1 1] should be considered to have 2 patterns and the matrix [1 1 1 1 1 1] should be considered to have only 1 pattern. Can anyone help? Thanks in advance!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 4 月 26 日
A=[ 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 ];
a=[0 A 0];
ii1=strfind(a,[0 1]);
ii2=strfind(a,[1 0])-1;
out=fix((ii2-ii1+1)/4)
  1 件のコメント
Renee
Renee 2014 年 4 月 26 日
Thank you so much!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDiscrete Math についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by