I have a large matrix from which I would like to assemble a collection of submatrices. If my matrix is ââNxN and the submatrix size is MxM, I want to collect the submatrices I=(N - M + 1)^2 . In other words, I need one MxM submatrix for each element of the original matrix, which can be in the upper left corner of such a matrix.
Here is the code I have:
for y = 1:I for x = 1:I index = (y - 1) * I + x; block_set(index) = big_mat(x:x+M-1, y:y+M-1) endfor endfor
The result, if a) is incorrect, and b) implying that there is something in the big_mat(x:x+M-1, y:y+M-1) expression big_mat(x:x+M-1, y:y+M-1) that can get me what I want, without the need for two cycles. Any help would be greatly appreciated
source share