# How to split data in a matrix

Consider the matrix 'm1' :

m1 = RandomReal[{0, 1}, {50, 50}];
MatrixForm@m1


The partition of this matrix into non-overlapping rectangles (arranged horizontally)

looks like this:

a=5;
b=10;
part1 = Partition[m1, {a, b}];


The question is how to part this area into rectangles with sides a, b, but arranged parallel to the diagonal (45 degree), that is, like this:

At the same time, those that are not a full rectangle must be neglected. One idea is to rotate the 'm1' matrix 45 degree and then use the command Partition[xxx, {a, b}]; and filter out 'full rectangles'.

There are some details that need to be filled in the question. Is the input matrix treated as 'image-like' or 'grid-like' when it comes to extraction? If it's 'grid-like' then the question is ill-posed because it depends on font-size of the matrix, spacing, how you'd treat numbers going over boundaries, etc.

If it is 'image-like' then non-axis aligned rectangles don't really exist and must have jagged edges. If you can accept that, then we can lean on Mathematica's image processing capabilities to produce a rotated mask from which we can extract the groups of pixels

m1 = RandomReal[{0, 1}, {50, 50}];
{a, b} = {5, 10};
chunksize = Ceiling[Dimensions[m1]/{a, b}];

(* Build a mask image of the grid *)
Table[
Image[ConstantArray[i, Reverse@chunksize], "Bit16"], {i, 1,
a*b}], a
]], "Bit16"];

(* Use a bit16 image so you'll have enough labels. Use
nearest-sampled so we don't create fractional interpolated labels *)
Round@ImageData@
Resampling -> "Nearest"];

(* Let's see what this looks like when rotated *)

(* Pick out the data in m1 corresponding to each value of our mask *)

parts = Association[


Each piece 'id' in the original partition (from top left to bottom right), now corresponds to the rotated piece in the mask. The parts association contains the pixel/matrix values that lie beneath it when superimposed on m1.

If you needed the mask to cover the edges and extend forever, like in your picture, then you could do something like this:

tmp = Image[i = 1; Table[i++, {x, 70}, {y, 70}]];
tmp = ImageResize[tmp, {10, 5}*ImageDimensions[tmp],
Resampling -> "Nearest"];