title: fillmissing with only last 5 observations instead of all
body: <p>I am using Matlab's <code>fillmissing</code> <a href="https://nl.mathworks.com/help/matlab/ref/fillmissing.html" rel="nofollow noreferrer">function</a> to fill missing values. </p>
  
  <p>If you have a matrix that looks as follows:</p>
  
  <pre><code>A = rand(10,2);
  A(end-5:end,1) = NaN;
  
  % this gives: 
  A =
  
      0.8147    0.1576
      0.9058    0.9706
      0.1270    0.9572
      0.9134    0.4854
         NaN    0.8003
         NaN    0.1419
         NaN    0.4218
         NaN    0.9157
         NaN    0.7922
         NaN    0.9595
  </code></pre>
  
  <p>And you apply the function fillmissing as follows:</p>
  
  <pre><code>Afilled = fillmissing(A, 'previous')
  </code></pre>
  
  <p>then the corresponding matrix will look as follows:</p>
  
  <pre><code>Afilled =
  
      0.8147    0.1576
      0.9058    0.9706
      0.1270    0.9572
      0.9134    0.4854
      0.9134    0.8003
      0.9134    0.1419
      0.9134    0.4218
      0.9134    0.9157
      0.9134    0.7922
      0.9134    0.9595
  </code></pre>
  
  <p>Now however, the function does not take into account how many observations were actually missing (in this case 6). </p>
  
  <p>I am looking for a way to take the number of observations into account before taking the last value. For example, only fill the missing observations based on the last 5 observations:</p>
  
  <pre><code>Afilled2 =
  
      i=1               0.8147    0.1576
      i=2               0.9058    0.9706
      i=3               0.1270    0.9572
      i=4               0.9134    0.4854
      i=5 % missing 1   0.9134    0.8003
      i=6 % missing 2   0.9134    0.1419
      i=7 % missing 3   0.9134    0.4218
      i=8 % missing 4   0.9134    0.9157
      i=9 % missing 5   0.9134    0.7922
      i=10              NaN       0.9595
  </code></pre>