title: How do I iterate through each element in an n-dimensional matrix in MATLAB?
body: <p>I have a problem. I need to iterate through every element in an n-dimensional matrix in MATLAB. The problem is, I don't know how to do this for an arbitrary number of dimensions. I know I can say</p>
  
  <pre><code>for i = 1:size(m,1)
      for j = 1:size(m,2)
          for k = 1:size(m,3)
  </code></pre>
  
  <p>and so on, but is there a way to do it for an arbitrary number of dimensions?</p>