In the following matrix I'm trying to identify every largest rectangles formed by 1's as shown in the picture. Rectangles can have just one row only if they have more than 3 columns. Rectangles can have just one column only if they have more than 3 rows. Rectangles should have less than maxcol columns and maxrow rows and more than mincol and minrow. In the picture mincol=minrow=2. maxrow=maxcolumn=6
Tried to use the subset function but it provides 1's submatrixs not every superimposed rectangles.
mdat <- matrix(c(0,1,1,1,0,0,0,1,0,1,1,1,1,1,1,1,1,1,0,1,0,1,1,0), nrow = 4, ncol = 6, byrow = TRUE)
dimnames(mdat) <- list( c("row1", "row2", "row3","row4"), c("col1", "col2", "col3", "col4","col5","col6"))