So let's say we have this matrix:
0 0 0 0 0 0 0 0
0 1 1 1 0 0 0 0
0 1 1 1 0 0 0 0
0 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0
0 0 0 0 1 1 1 0
0 0 0 0 1 1 1 0
And we need those outputs:
Submatrix 1:
1 1 1
1 1 1
1 1 1
Submatrix 2:
1 1 1
1 1 1
The matrix size can vary, so can the submatrix sizes but they will have either square or rectangle shape. And is only 0 and 1.
How can i do that? Is there any algorithm to do that?
for (i=0; i<m;i++){
for (j=2; j<n; j++){
if ( A[i+1,j]==1 && A[i,j+1]==1 || A[i+1,j]==1 && A[i,j-1]==1 || A[i-1,j]==1 && A[i,j+1]==1 || A[i-1,j]==1 && A[i,j-1]==1 || A[i-1,j]==1 && A[i+1,j]==1 && A[i,j-1]==1 && A[i,j+1]==1 )
B[i,j]=A[i,j];
}
}
This is the first ideea that comes to my mind, but i don't know how to stop after i'm done with the first block of ones, and in the end the matrix B is the same as matrix A. Also i don't know how to set the submatrix size to be exactly the size that it needs to be. For now i'm only trying to break the big matrix in 2. Should i allocate the submatrix dynamically?