I am trying to identify the consecutive three-column groups that have >2 instances of “1” in this matrix.
A=[1 2 3 4 5 6 7 8 9 10 11 0 0 0 0 0 0;
0 1 2 3 4 5 6 7 8 9 10 11 0 0 0 0 0;
0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 0 0;
1 2 3 4 5 6 7 8 9 10 11 0 0 0 0 0 0;
0 0 1 2 3 4 5 6 7 8 9 10 11 0 0 0 0;
0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 0 0]
Can anyone help?
For example, columns 1-3 have 4 instances of “1” (which is >2); columns 2-4 have only 2 instances of “1” (not >2); columns 3-5 have 3 instances of “1” (>2). None of the remaining three-column groups have >2 instances of “1”. So the desired results would be
[1 0 1 0 0 0 0 0 ... ]
A one line solution:
Result: