How to delete values in unqualified matrix rows?

I want to try to delete values in a binary matrix that do not have "n" times consecutive 1s with the following example :
matrix = [0 1 1 0 0 1 0 1 0 1 1 1 0 0];
checkmatrix(matrix,n);
when n = 1, the function returns :
[0 1 1 0 0 1 0 1 0 1 1 1 0 0]
when n = 2, the function returns :
[0 1 1 0 0 0 0 0 0 1 1 1 0 0]
when n = 3, the function returns :
[0 0 0 0 0 0 0 0 0 1 1 1 0 0]
when n = 4, the function returns :
[0 0 0 0 0 0 0 0 0 0 0 0 0 0]
is there a special syntax or is there a specific method for solving this case?

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Release

R2017a

Asked:

on 30 Jul 2022

Answered:

on 30 Jul 2022

Community Treasure Hunt

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

Start Hunting!