Octave: Multiple submatrices from a matrix
- by fbrereto
I have a large matrix from which I would like to gather a collection of submatrices. If my matrix is NxN and the submatrix size is MxM, I want to collect I=(N - M + 1)^2 submatrices. In other words I want one MxM submatrix for each element in the original matrix that can be in the top-left corner of such a matrix.
Here's 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 output if a) wrong, and b) implying there is something in the big_mat(x:x+M-1, y:y+M-1) expression that can get me what I want without needing the two for loops. Any help would be much appreciated