title: FOR loop over column vector vs row vector
body: <p>I was just writing a "kinda-foreach" loop in Matlab and encountered this strange behavior:</p>
  
  <p>I have the matrix A:</p>
  
  <pre><code>A = [
   3
   9
   5
   0];
  </code></pre>
  
  <p>And I want to use a <code>foreach</code> loop (as explained <a href="https://stackoverflow.com/questions/408080/is-there-a-foreach-in-matlab-if-so-how-does-it-behave-if-the-underlying-data-c">here</a>) on the A.</p>
  
  <p>If I write this:</p>
  
  <pre><code>for i = A
       disp('for')
       i    
  end
  </code></pre>
  
  <p>The result will be:</p>
  
  <pre><code>for
  
  i =
  
       3
       9
       5
       0
  </code></pre>
  
  <p>But when I use the transpose, the result will change:</p>
  
  <pre><code>for i = A'
       disp('for')
       i    
  end
  </code></pre>
  
  <p>Result:</p>
  
  <pre><code>for
  
  i =
  
       3
  
  for
  
  i =
  
       9
  
  for
  
  i =
  
       5
  
  for
  
  i =
  
       0
  </code></pre>
  
  <p>Which is the result I want.</p>
  
  <p>Can anybody explain what's going on here? What's the difference between these two cases?</p>