How to delete values in unqualified matrix rows?
Show older comments
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?
Answers (1)
Walter Roberson
on 30 Jul 2022
bwareafilt(logical(matrix), [n inf])
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!