title: Split matrix into submatrices
body: <p>I found a solution to a similar question that breaks up a matrix into a set of non-overlapping sub-matrices when the matrix may not be square (as it may not be in my situation) <a href="https://stackoverflow.com/questions/24299171/function-to-split-a-matrix-into-sub-matrices-in-r">Function to split a matrix into sub-matrices in R</a>.  However, in my case I want the matrices to be overlapping.  Using the following matrix as an example:</p>
  
  <pre><code>M &lt;- matrix(1:20, 5)
  
  #     [,1] [,2] [,3] [,4]
  #[1,]    1    6   11   16
  #[2,]    2    7   12   17
  #[3,]    3    8   13   18
  #[4,]    4    9   14   19
  #[5,]    5   10   15   20
  </code></pre>
  
  <p>If I choose the number of rows and columns of the sub-matrices to be 4 and 4 respectively then the sub-matrices returned should be every possible overlapping 4X4 sub matrix that completely fits within the boundary of the original matrix (this is another place where the answer to this question may need to be different to the question I have referenced).  In my example there would only be two sub matrices that should be returned.  <code>M[1:4,1:4]</code> and <code>M[2:5,1:4]</code>.  I should be able to choose any arbitrary size of sub matrix.  I can't seem to find any examples of extracting overlapping sub matrices, but I may be over-thinking this one.  Does anyone have any ideas on the best way to go about this?</p>