title: General method to find submatrix in matlab matrix
body: <p>I am looking for a 'good' way to find a matrix (pattern) in a larger matrix (arbitrary number of dimensions).</p>
  
  <p>Example:</p>
  
  <pre><code>total = rand(3,4,5);
  sub = total(2:3,1:3,3:4);
  </code></pre>
  
  <p>Now I want this to happen:</p>
  
  <pre><code>loc = matrixFind(total, sub)
  </code></pre>
  
  <p>In this case <code>loc</code> should become <code>[2 1 3]</code>. </p>
  
  <p>For now I am just interested in finding one single point (if it exists) and am not worried about rounding issues. It can be assumed that <code>sub</code> 'fits' in <code>total</code>. </p>
  
  <hr>
  
  <p>Here is how I could do it for 3 dimensions, however it just feels like there is a better way:</p>
  
  <pre><code>total = rand(3,4,5);
  sub = total(2:3,1:3,3:4);
  loc = [];
  for x = 1:size(total,1)-size(sub,1)+1
      for y = 1:size(total,2)-size(sub,2)+1
          for z = 1:size(total,3)-size(sub,3)+1
              block = total(x:x+size(sub,1)-1,y:y+size(sub,2)-1,z:z+size(sub,3)-1);
              if isequal(sub,block)
                  loc = [x y z]
              end
          end
      end
  end
  </code></pre>
  
  <hr>
  
  <p>I hope to find a workable solution for an arbitrary number of dimensions. </p>