%%
h=figure;
parentpath = cd(cd('..'));
msize=5;
lsize=2;
yaxisLim=[40,100];
axLabS=12; %size of latex labels
axnLat=12; %size od non latex labels
axFS=10;
modelInf={'FE','NE-0.90','NE-00','NV'};
modelInf=cellstr(modelInf);
nSubs=sum(length(unique(data.subData.sub)));
dist=1.75;
cond=unique(data.subData.sigXcond);
for r=1:length(modelInf)
    for j=1:length(unique(data.subData.sigXcond))
        subplot(3,4,r+(j-1)*4)
        hold on
        sca=100;
        errorbar(m2visAngle(dist,mean(data.subData.sigVcond(:,data.subData.sigXcond==cond(j)),2)),data.subData.meanCor2D(:,j)*sca,data.subData.stdCor2D(:,j)./sqrt(nSubs)*sca,'o','MarkerEdgeColor','None','MarkerFaceColor','b','MarkerSize',msize,'LineWidth',1,'Color','b')
        errorbar(m2visAngle(dist,mean(data.subData.sigVcond(:,data.subData.sigXcond==cond(j)),2)),data.subData.meanCor3D(:,j)*sca,data.subData.stdCor3D(:,j)./sqrt(nSubs)*sca,'o','MarkerEdgeColor','None','MarkerFaceColor','r','MarkerSize',msize,'LineWidth',1,'Color','r')
        %drawline(E.wei80pThresh(data.subData.sigXcond==cond(j)&data.subData.dim==0&data.subData.sub==l),'dir','vert','lim',[0.3 1],'linestyle','--','color',[0 0 1])
        %plot(x,mean(E.weiCurve(:,data.subData.sigXcond==cond(j)&data.subData.dim==0),2)*sca,'b')
        %plot(x,mean(E.weiCurve(:,data.subData.sigXcond==cond(j)&data.subData.dim==1),2)*sca,'r')
        
        
        
        %load(S(I(f(1))).name)
        plot(m2visAngle(dist,mean(data.subData.sigVcond(:,data.subData.sigXcond==cond(j)),2)),squeeze(data.model.modelBestResp(j,1:10,r))*sca,'b','LineWidth',lsize)
        plot(m2visAngle(dist,mean(data.subData.sigVcond(:,data.subData.sigXcond==cond(j)),2)),squeeze(data.model.modelBestResp(j,11:end,r))*sca,'r','LineWidth',lsize)
        
        
        
        
        for k=1:length(unique(data.subData.sub)) %change to be independent
            uni=unique(data.subData.sub);
            l=uni(k);
            tmp2D=data.subData.propCor(:,data.subData.sigXcond==cond(j)&data.subData.dim==0&data.subData.sub==l);
            tmp3D=data.subData.propCor(:,data.subData.sigXcond==cond(j)&data.subData.dim==1&data.subData.sub==l);
            if isempty(tmp2D)
                data.subData.subCor2D(:,l,j)=nan;
            else
                data.subData.subCor2D(:,l,j)=data.subData.propCor(:,data.subData.sigXcond==cond(j)&data.subData.dim==0&data.subData.sub==l);
            end
            if isempty(tmp3D)
                data.subData.subCor3D(:,l,j)=nan;
            else
                data.subData.subCor3D(:,l,j)=data.subData.propCor(:,data.subData.sigXcond==cond(j)&data.subData.dim==1&data.subData.sub==l);
            end
        end
        
        %plot(n,E.meanCor(:,j),'o')
        %plot(m2visAngle(dist,data.subData.sigVcond(:,data.subData.sigXcond==cond(j))),data.subData.propCor(:,data.subData.sigXcond==cond(j)))
        %plot(m2visAngle(dist,data.subData.sigVcond(:,data.subData.sigXcond==cond(j)&data.subData.dim==0)),data.subData.propCor(:,data.subData.sigXcond==cond(j)&data.subData.dim==0),'bo')
        %plot(m2visAngle(dist,data.subData.sigVcond(:,data.subData.sigXcond==cond(j)&data.subData.dim==1)),data.subData.propCor(:,data.subData.sigXcond==cond(j)&data.subData.dim==1),'ro')
        if j==1
            text(0.19,120,[modelInf{r}],'FontSize',axnLat)
        end
        if j==3
            xlabel('(deg/frame)','fontsize',axLabS)
        else
               set(gca,'xticklabel',[])
        end
        if r==1
            ylabel('% Correct','Fontsize',axnLat)
        else
                    set(gca,'yticklabel',[])
        end
        %    if r==2||r==3
        %set(gca,'YTick',[])
        %    end
        %        if j==1||j==2
        %set(gca,'XTick',[])
        %end
        if j==1&&r==1
            legend('2D Data','3D Data','2D Model','3D Model')
        end
        legend boxoff
        set(gca,'FontSize',axFS)
        set(gca,'TickDir','in')
        set(gca,'TickDir','in')
        set(gca, 'Ticklength', [0.02 0])
        set(gca, 'LineWidth', 1.5)
        if r==1
            title([num2str(m2visAngle(dist,cond(j))),' (deg)'],'fontsize',axLabS)
        end
        set ( gca, 'xdir', 'reverse' )
        xlim([0 0.21])
        ylim([30 100])
        set(h,'Position',[100 100 1200 500])
        NumTicks = 3;
        L = get(gca,'XLim');
        NumTicks2 = 4;
        L2= get(gca,'YLim');
        set(gca,'XTick',linspace(L(1)+0.05,L(2)-0.01,NumTicks))
        set(gca,'YTick',linspace(L2(1)+10,L2(2),NumTicks2))
        
        
    end
   
end

fig=gcf;
%# centimeters units
%a4=21 by 29.7
X = 20;                  %# A3 paper size
Y = 20;                  %# A3 paper size
xMargin = 1;               %# left/right margins from page borders
yMargin = 1;               %# bottom/top margins from page borders
xSize = X - 2*xMargin;     %# figure size on paper (widht & hieght)
ySize = Y - 2*yMargin;     %# figure size on paper (widht & hieght)

% set(fig, 'Position', [100, 100, 1049, 895]);

%# create figure/axis


%# figure size displayed on screen (50% scaled, but same aspect ratio)
set(fig, 'Units','centimeters', 'Position',[0 0 xSize ySize])
movegui(fig, 'center')

%# figure size printed on paper
set(fig, 'PaperUnits','centimeters')
set(fig, 'PaperSize',[X Y])
set(fig, 'PaperPosition',[xMargin yMargin xSize ySize])
set(fig, 'PaperOrientation','portrait')
%print('D:\Surf\PhD\Phd_writing\PhD\MOT\MOT2d-3d Paper\figures\datModelFit', '-dsvg', '-r400')
%print('D:\Surf\PhD\Phd_writing\PhD\MOT\MOT2d-3d Paper\figures\datModelFit', '-dpdf', '-r400')
%print(fullfile(parentpath,'/figures/datModelFit'), '-dsvg', '-r400')
print(fullfile(parentpath,'/figures/datModelFit'), '-dpdf', '-r400')
