Octave: Multiple submatrices from a matrix

Posted by fbrereto on Stack Overflow See other posts from Stack Overflow or by fbrereto
Published on 2010-04-26T20:26:02Z Indexed on 2010/04/26 20:33 UTC
Read the original article Hit count: 414

Filed under:
|
|
|
|

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

© Stack Overflow or respective owner

Related posts about octave

Related posts about matlab