function LoopMCMCMetropolis(nexptos,N) 

% LOOPMCMCMETROPOLIS Runs the Metropolis algorithms mutiple times
%
% LoopMCMCMetropolis(nexptos,N)
% nexptos: number of times
% N: array with number of samples

% APRENDIZAJE AUTOMÁTICO (G. Pajares y J. M. de la Cruz, Eds.)
% Editorial: RA-MA
% Capítulo 7 y 8: Monte Carlo I y II
% Autores: Eva Besada-Portas, Sergey M. Plis


 draw=0;                   % Draw results inside each method
 
 pfun=DefineFunction('pC'); %pfun funtion 
  
 load StartMCMCData %s0
 snew=s0;

 hmN=length(N);
 fmean={};
 for l=1:hmN
    N(l)               
    for k=1: nexptos
        disp(sprintf('Experiment:%d',k));
    
        s0 = snew(k,l);

        sigma=1;
        qfun=DefineFunction('qgaussian',sigma);
        [samplesMC]=MarkovChain(N(l),DefineFunction('ChainMetropolis',pfun,qfun),s0,draw);
        fmean{1}(k,l)=mean(samplesMC);
          
        sigma=5;
        qfun=DefineFunction('qgaussian',sigma);
        [samplesMC]=MarkovChain(N(l),DefineFunction('ChainMetropolis',pfun,qfun),s0,draw);
        fmean{2}(k,l)=mean(samplesMC);
       
        sigma=10;
        qfun=DefineFunction('qgaussian',sigma);
        [samplesMC]=MarkovChain(N(l),DefineFunction('ChainMetropolis',pfun,qfun),s0,draw);
        fmean{3}(k,l)=mean(samplesMC);
                    
    end
 end


save('LoopMCMCMetropolisData','fmean','qfun','N');

 