title: Running Matlab script many times
body: <p>So I have a matlab.m file script. When the file runs. It generates a vector. I want to save that vector and rerun the script all over again. How do I put a loop on the entire script file and create a vector_{i}, where the index enters the name of the file? I would post the code but it wont work without the data on my desktop. </p>
  
  <pre><code>[data,labels]=xlsread('C:\Users\Hilbert\Desktop\matlab\matlabdata_abe.xlsx');
  
  
  gdp=log(data(:,1)./lagmatrix(data(:,1),1)) %GDP
  ip=log(data(:,2)./lagmatrix(data(:,2),1)) %IP
  tnx=data(:,3) %TNX
  m2=log(data(:,4)./lagmatrix(data(:,4),1)) %M2
  cpi=log(data(:,5)./lagmatrix(data(:,5),1)) %CPI
  ffed=log(data(:,6)./lagmatrix(data(:,6),1)) %FedFund
  
  
  Dgdp=gdp
  inflation=cpi
  Dm2=m2
  ffr_=ffed
  
  
  data=[Dgdp(54:length(cpi)), inflation(54:length(cpi)), Dm2(54:length(cpi)), ffr_(54:length(cpi)) ]; 
  
  data_L1=lagmatrix(data,1)
  data_L2=lagmatrix(data,2)
  data_L3=lagmatrix(data,3)
  data_L4=lagmatrix(data,4)
  mat=[ones(1,size(data_L1',2));data_L1';data_L2';data_L3';data_L4']
  mat=mat(:,5:end)
  
  X=[data';data_L1';data_L2';data_L3']
  X=X(:,5:end)
  
  
  mat=mat';
  X=X'
  Fhat=(inv(mat'*mat) * mat'*X)';
  
  nobs=size(data,1)
  p=4
  
  yhat= mat*Fhat'
  yhat=yhat(:,1:4)
  data_sample=data(5:nobs,:)
  res=data_sample - yhat
  
  res_{loopindexnumber}=res  %saves the vector and re-runs the entire cost again the idea is to bootstrap the data by running many simulations and saving the residual vector
  </code></pre>