title: Moving average ignoring NaN
body: <p>I am trying to compute a moving average on multiple columns of a matrix. After reading some answers on stackoverflow, namely <a href="https://stackoverflow.com/questions/22598902/a-moving-average-with-different-functions-and-varying-time-frames">this</a> one, it seemed that the <code>filter</code> function was the way to go. However, it does not ignore <code>NaN</code> elements, and I would like to do this ignoring <code>NaN</code> elements in the spirit of the function <code>nanmean</code>. Below a sample code:</p>
  
  <pre><code>X = rand(100,100); %generate sample matrix
  X(sort(randi([1 100],1,10)),sort(randi([1 100],1,10))) = NaN; %put some random NaNs 
  windowlenght = 7;
  MeanMA = filter(ones(1, windowlenght) / windowlenght, 1, X);
  </code></pre>