%%
parentpath = cd(cd('..'));
figure
C = {'m','c','g','r'};
C = cellstr(C);
C=linspecer(6);
msize=5; %marker size
lsize=2; %line size
axLabS=12; %size of latex labels
axnLat=12; %size od non latex labels
axFS=10; %tick label size
modelInf={'FE','NE-cd','NE-id','NV'}; %model names
modelInf=cellstr(modelInf);
nSub=sum(length(unique(data.subData.sub)));
dist=1.75;
cond=unique(data.subData.sigXcond);
for r=1:length(modelInf)
    hold all
    diffCond2D(1)=[mean(data.subData.wei80pThresh(data.subData.dim==0&data.subData.sigXcond==cond(1)))];
    diffCond2D(2)=[mean(data.subData.wei80pThresh(data.subData.dim==0&data.subData.sigXcond==cond(2)))];
    diffCond2D(3)=[mean(data.subData.wei80pThresh(data.subData.dim==0&data.subData.sigXcond==cond(3)))];
    diffSTD2D(1)=[std(data.subData.wei80pThresh(data.subData.dim==0&data.subData.sigXcond==cond(1)))/sqrt(nSub)];
    diffSTD2D(2)=[std(data.subData.wei80pThresh(data.subData.dim==0&data.subData.sigXcond==cond(2)))/sqrt(nSub)];
    diffSTD2D(3)=[std(data.subData.wei80pThresh(data.subData.dim==0&data.subData.sigXcond==cond(3)))/sqrt(nSub)]; 
    
    diffCond3D(1)=[mean(data.subData.wei80pThresh(data.subData.dim==1&data.subData.sigXcond==cond(1)))];
    diffCond3D(2)=[mean(data.subData.wei80pThresh(data.subData.dim==1&data.subData.sigXcond==cond(2)))];
    diffCond3D(3)=[mean(data.subData.wei80pThresh(data.subData.dim==1&data.subData.sigXcond==cond(3)))];
    diffSTD3D(1)=[std(data.subData.wei80pThresh(data.subData.dim==1&data.subData.sigXcond==cond(1)))/sqrt(nSub)];
    diffSTD3D(2)=[std(data.subData.wei80pThresh(data.subData.dim==1&data.subData.sigXcond==cond(2)))/sqrt(nSub)];
    diffSTD3D(3)=[std(data.subData.wei80pThresh(data.subData.dim==1&data.subData.sigXcond==cond(3)))/sqrt(nSub)]; 
    
    if r==1
        errorbar(m2visAngle(dist,cond),diffCond2D,diffSTD2D,'k--','LineWidth',lsize)
        errorbar(m2visAngle(dist,cond),diffCond3D,diffSTD3D,'k-','LineWidth',lsize)
    end
    diffCondMod3D(1)=data.model.wei80pThreshMod3D(1,r);
    diffCondMod3D(2)=data.model.wei80pThreshMod3D(2,r);
    diffCondMod3D(3)=data.model.wei80pThreshMod3D(3,r);
    
    
    diffCondMod2D(1)=data.model.wei80pThreshMod2D(1,r);
    diffCondMod2D(2)=data.model.wei80pThreshMod2D(2,r);
    diffCondMod2D(3)=data.model.wei80pThreshMod2D(3,r);
    
    plot(m2visAngle(dist,cond),diffCondMod2D,'--','LineWidth',lsize,'color',C(r+1,:))
    plot(m2visAngle(dist,cond),diffCondMod3D,'-','LineWidth',lsize,'color',C(r+1,:))
    legendInfo{1}='Data 2D';
    legendInfo{2}='Data 3D';
    legendInfo{r+(r+1)}=[modelInf{r},' 2D'];
    legendInfo{r+(r+2)}=[modelInf{r},' 3D'];
    %legend('Data','FE','NE','NV')
    ylabel('(deg/frame)','fontsize',axLabS)
    xlabel('(deg)','fontsize',axLabS)
    ylim([0 0.2])
    xlim([2,4])
    setTicks(5,3,2,2)
    xlim([1.5,4.5])
    set(gca,'TickDir','in')
    set(gca, 'Ticklength', [0.02 0])
    set(gca, 'LineWidth', 1.5)
    legend boxoff
    
end
%# centimeters units
%a4=21 by 29.7
X = 10;                  %# A3 paper size, when box is deleted lose approx 2 cm
Y = 12;                  %# A3 paper size %acurate pretty much
xMargin = 0;               %# left/right margins from page borders
yMargin = 0;               %# 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

fig=gcf;
%# figure size displayed on screen (50% scaled, but same aspect ratio)
legend(legendInfo,'Location','northeast')
legend boxoff
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(fullfile(parentpath,'/figures/interaction'), '-dsvg', '-r400')
print(fullfile(parentpath,'/figures/interaction'), '-dpdf', '-r400')
