title: Initialize MATLAB matrix based on indices
body: <p>I'm trying to create a matrix M satisfying:</p>
  
  <pre><code>M(i,j) = f(i,j)
  </code></pre>
  
  <p>for some f. I can do elementwise initialization through say <code>M = zeros(m,n)</code> then looping. For example (in Octave):</p>
  
  <pre><code>M = zeros(m,n)
  for i = 1 : m
    for j = 1 : n
      m(i, j) = (i+j)/2;
    endfor
  endfor
  </code></pre>
  
  <p>But AFAIK loops are not the  optimal way to go with MATLAB. Any hints?</p>