title: Using MATLAB, how can I find the moving average?
body: <p>Using MATLAB, how can I find the 3-day moving average of a specific column of a matrix and append the moving average to that matrix?  I am trying to compute the 3-day moving average from bottom to top of the matrix.  I have provided my code:</p>
  
  <p>Given the following matrix a and mask:</p>
  
  <pre><code>a = [1,2,3;4,5,6;7,8,9;10,11,12;13,14,15;16,17,18];
  mask = ones(3,1);
  </code></pre>
  
  <p>I have tried implementing the conv command but I am receiving an error.  Here is the conv command I have been trying to use on the 2nd column of matrix a:</p>
  
  <pre><code>a(:,4) = conv(a(:,2),mask,'valid');
  </code></pre>
  
  <p>The output I desire is given in the following matrix:</p>
  
  <pre><code>desiredOutput = [1,2,3,5;4,5,6,8;7,8,9,11;10,11,12,14;13,14,15,0;16,17,18,0;]
  </code></pre>
  
  <p>If you have any suggestions, I would greatly appreciate it.  Thank you!</p>