title: What's the best way to iterate through columns of a matrix?
body: <p>I want to apply a function to all columns in a matrix with MATLAB. For example, I'd like to be able to call smooth on every column of a matrix, instead of having smooth treat the matrix as a vector (which is the default behaviour if you call <code>smooth(matrix)</code>).</p>
  
  <p>I'm sure there must be a more idiomatic way to do this, but I can't find it, so I've defined a <code>map_column</code> function:</p>
  
  <pre><code>function result = map_column(m, func)
      result = m;
      for col = 1:size(m,2)
          result(:,col) = func(m(:,col));
      end
  end
  </code></pre>
  
  <p>which I can call with:</p>
  
  <pre><code>smoothed = map_column(input, @(c) (smooth(c, 9)));
  </code></pre>
  
  <p>Is there anything wrong with this code? How could I improve it?</p>