%Figure 8, panels c and d 
colors=parula(9);
doanal = 1;

if doanal==1
field='f';
nvec=.999:-.001:.01;
proc='cc';
letts='a':'f';

icom=0;
imom1=[1,2,4,5,6,7,8];
imom2=[2,4,5,6,7,8,9];
mid50=nan(10,10,10);
mid50all=nan(10,10,10,240);

for kt=1:7
    for lt=kt:7
        icom=icom+1;
        combs(icom,:)=[imom1(kt) imom2(lt)];
        
        ci=num2str(imom2(lt));
        
        vars{1}=['cM',num2str(imom1(kt)),ci,num2str(imom1(kt)),ci,'type0'];
        vars{2}='bin';
        
        testset='../AMP_45_NP/output_4M_gamma/cc';
        testsetb=testset;
        
        read_nonparametric
        
        clear data
        
        for im=1:10
            imom=im-1;
            
            if imom~=3
                field='f';
            else
                field='c';
            end
            nonparametric_error_evolution
            
            lastreal = find(~isnan(data(end,:,1)),1,'last');
            datadiff=nan(1,ntest);
            for ii=1:lastreal
                errinds = find(data(:,ii,2)>=0.5,1,'last');
                datadiff(ii)=abs(data(errinds,ii,1)-data(errinds,ii,2));
            end
            mid50all(imom1(kt),imom2(lt),im,:)=datadiff;
            mid50(imom1(kt),imom2(lt),im)=mean(abs(datadiff),'omitnan');
        end
        
        if icom==14 || icom==18 || icom==25
            vars{1}=['cM03',num2str(imom1(kt)),ci,'type2'];
            vars{2}=['binM03',num2str(imom1(kt)),ci];
            
            testset='../AMP_45_NP/output_4M-v7/cc';
            testsetb=testset;
            
            read_nonparametric
            
            clear data
            
            for im=1:10
                imom=im-1;
                
                if imom~=3
                    field='f';
                else
                    field='c';
                end
                nonparametric_error_evolution
                
                lastreal = find(~isnan(data(end,:,1)),1,'last');
                datadiff=nan(1,ntest);
                for ii=1:lastreal
                    errinds = find(data(:,ii,2)>=0.5,1,'last');
                    datadiff(ii)=abs(data(errinds,ii,1)-data(errinds,ii,2));
                end
                mid50all2(imom1(kt),imom2(lt),im,:)=datadiff;
                mid502(imom1(kt),imom2(lt),im)=mean(abs(datadiff),'omitnan');
            end
        end
    end
end

save('midrain_errors_4M','mid50','mid50all','mid502','mid50all2')
beep

else
end

figure
subplot(2,2,3)
pcolor(.5:9.5,.5:9.5,mid50(:,:,1))
colorbar
xlabel('Full Moment')
ylabel('Full Moment')
title('(c) MNAE M0')


subplot(2,2,4)
pcolor(.5:9.5,.5:9.5,mid50(:,:,7))
colorbar
xlabel('Full Moment')
ylabel('Full Moment')
title('(d) MNAE M6')

avgerr = squeeze(mean(mid50all,[1 2],'omitnan'));