title: Error: Index exceeds matrix dimension in simulating AR process
body: <p>I have a data file of size 256 rows. I want to fit the data to a second order AR(2) process and then simulate the process after fitting. I have the following code but it returns error <strong>Index exceeds matrix dimensions.</strong> </p>
  
  <pre><code>whos y1
    Name      Size            Bytes  Class    Attributes
  
    y1        1x1              1712  cell  
  </code></pre>
  
  <p>whos coeff</p>
  
  <pre><code>is  1x3                24  double              
  </code></pre>
  
  <p>Please help in resolving the error. Also, how do I check with a plot that the original data and the fitted data are almost same and get the error ?</p>
  
  <pre><code>load('b1.dat');
  y1=b1(:);
  
  if ~iscell(y1); y1 = {y1}; end
  
  model = ar(y1, 2, 'ls');
  
  
  
  coeffs = model.a;
  ar_coeff1=[coeff(2) coeff(3)]
  
  
  %simulate
  for i =3 : 256
  
     y1(i) = coeff(2) *y1(i-1) +coeff(3)*y1(i-2) ;  **% This line returns error**
  
  end
  </code></pre>