clear
load('/Volumes/iamdavecampbell/MCMC many times/1000 random data sets/FhN MCMC data set_38.mat')
time=[time;time];  % stack time
Y=[Ydata(:,1);Ydata(:,2)]; % stack data
beta0=[.5,.5,1,-.5,.5];
fun=@NLS_FhN

[beta,r,J,COVB,mse] = nlinfit(time,Y,fun,beta0)

[Ypred,delta] = nlpredci(fun,time,beta,r,'jacobian',J)
n=length(Ydata(:,1));
CI_Y=repmat(Ypred,1,3)+[-delta,zeros(2*n,1),delta];

plot(time(1:n),CI_Y(1:n,:),'b',time(1:n),Ydata(:,1),'.b',...
    time(1:n),CI_Y(n+1:2*n,:),'k',time(1:n),Ydata(:,2),'.k')



CI_NLS =  nlparci(beta,r,'jacobian',J);
[CI_NLS(:,1),beta',CI_NLS(:,2)]

