1function [zWin,yn,w1]=targmc(zPrev,z,b,n,order,w,y)
 2
 3% Select the data window for this iteration
 4  if n <= order  % feed in supplied past values ahead of z
 5        zWin = [zPrev(end-order+n+1:end,:); z(1:n,:)];
 6    else  % need only data from given z
 7        zWin = z(n-order+1:n,:);
 8  end 
 9  
10%initial w, and calculate output y 
11y(n) = b(n) - sum(diag(w'*zWin));
12
13%check y inf or not
14  if ~isfinite(y(n)), error('Output has blown up'), end
15  yn=y;
16  w1=w;
17end
18