Bläddra i källkod

gin commit from ck-NINux

New files: 27
Modified files: 16
Chris Klink 1 år sedan
förälder
incheckning
69cac589f2
43 ändrade filer med 7372 tillägg och 0 borttagningar
  1. 1 0
      DATA/B20140212-block-3-Wave.mat
  2. 1 0
      DATA/EYE.mat
  3. BIN
      DATA/Hardcoded_SOA_FG_sel.mat
  4. 1 0
      DATA/MAPPINGS/RF_B.mat
  5. 1 0
      DATA/MAPPINGS/RF_C.mat
  6. BIN
      DATA/STIMCURRENTS.mat
  7. 1 0
      DATA/V1FG_Selected2_5p.mat
  8. 1 0
      DATA/V1MS_CAC.mat
  9. 1 0
      DATA/V1MS_FIG.mat
  10. 1 0
      DATA/V1MS_GND.mat
  11. BIN
      DATA/V1V1.mat
  12. BIN
      DATA/V1V1_FG_1p.mat
  13. BIN
      DATA/V1V1_FG_5p.mat
  14. 1 0
      DATA/V1V1_Selected2_1p.mat
  15. 1 0
      DATA/V1V1_Selected_1p.mat
  16. BIN
      DATA/V1V1_spikes.mat
  17. 1 0
      DATA/V4MS_CAC.mat
  18. 1 0
      DATA/V4MS_CAC_V4.mat
  19. 1 0
      DATA/V4MS_FIG.mat
  20. 1 0
      DATA/V4MS_GND.mat
  21. 1 0
      DATA/ckV1MS.mat
  22. 1 0
      DATA/ckV4MS.mat
  23. 14 0
      README.md
  24. 439 0
      SCRIPTS/FUNCTIONS/FB_FIGURES.m
  25. 491 0
      SCRIPTS/FUNCTIONS/FF_FIGURES.m
  26. 1205 0
      SCRIPTS/FUNCTIONS/FG_FIGURES.m
  27. 983 0
      SCRIPTS/FUNCTIONS/FG_spikes_ms5p.asv
  28. 976 0
      SCRIPTS/FUNCTIONS/FG_spikes_ms5p.m
  29. 374 0
      SCRIPTS/FUNCTIONS/SACCADE_Analysis.m
  30. 797 0
      SCRIPTS/FUNCTIONS/STRAT_FIGURES.m
  31. 96 0
      SCRIPTS/FUNCTIONS/SUPPORT/Check_IndV1.m
  32. 281 0
      SCRIPTS/FUNCTIONS/SUPPORT/RFpos.m
  33. BIN
      SCRIPTS/FUNCTIONS/SUPPORT/SelectFG.fig
  34. 199 0
      SCRIPTS/FUNCTIONS/SUPPORT/SelectFG.m
  35. 67 0
      SCRIPTS/FUNCTIONS/SUPPORT/micsaccdeg.m
  36. 203 0
      SCRIPTS/FUNCTIONS/SUPPORT/preProcessV1MS.m
  37. 211 0
      SCRIPTS/FUNCTIONS/SUPPORT/preProcessV1MS_S7.m
  38. 197 0
      SCRIPTS/FUNCTIONS/SUPPORT/preProcessV4MS.m
  39. 189 0
      SCRIPTS/FUNCTIONS/SUPPORT/preProcessV4MS_S7.m
  40. 14 0
      SCRIPTS/FUNCTIONS/SUPPORT/print_figure.m
  41. 7 0
      SCRIPTS/FUNCTIONS/SUPPORT/regressionTTest.m
  42. 521 0
      SCRIPTS/FUNCTIONS/V1V1_spikes_ms1p.m
  43. 92 0
      SCRIPTS/main.m

+ 1 - 0
DATA/B20140212-block-3-Wave.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s204659646--84ca93068b397743325e101b493856cb

+ 1 - 0
DATA/EYE.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s105153473--89284b6cc211aff1b85256dbf0201434

BIN
DATA/Hardcoded_SOA_FG_sel.mat


+ 1 - 0
DATA/MAPPINGS/RF_B.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s21013461--eb3a68b97621264bfc44fa8897e84ceb

+ 1 - 0
DATA/MAPPINGS/RF_C.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s23962674--ee9522bd6b7d02c62f2e5db6bb4cb721

BIN
DATA/STIMCURRENTS.mat


+ 1 - 0
DATA/V1FG_Selected2_5p.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s40810891--da478c69ce9be0713a3ee9eea66a4ac4

+ 1 - 0
DATA/V1MS_CAC.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s28728897--a73a3d54cbce2a29753eb0e83b4706ba

+ 1 - 0
DATA/V1MS_FIG.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s28935510--264284cc0a54a49ede1b503963fb61e8

+ 1 - 0
DATA/V1MS_GND.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s28709891--0b8e0cd7e56069c53a5b279605b36723

BIN
DATA/V1V1.mat


BIN
DATA/V1V1_FG_1p.mat


BIN
DATA/V1V1_FG_5p.mat


+ 1 - 0
DATA/V1V1_Selected2_1p.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s1115786820--57bf69025715cfa460e1ea92ff307594

+ 1 - 0
DATA/V1V1_Selected_1p.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s2135396321--83ddc439e52e42f2068ba5f4635aa43f

BIN
DATA/V1V1_spikes.mat


+ 1 - 0
DATA/V4MS_CAC.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s48159382--66a2eb7575e309aa0f56be057d6cdf43

+ 1 - 0
DATA/V4MS_CAC_V4.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s49777741--98d68282b65283fcf70197caa7cad164

+ 1 - 0
DATA/V4MS_FIG.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s46728118--b8f4b4cb53ffbb9a614cbd913a42ca76

+ 1 - 0
DATA/V4MS_GND.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s48559886--de7882cedd58a60cd4b8410c78a1adad

+ 1 - 0
DATA/ckV1MS.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s28446640--62b4cce4662b6d5816d8616d9bc1af80

+ 1 - 0
DATA/ckV4MS.mat

@@ -0,0 +1 @@
+/annex/objects/MD5-s48031893--60e96dc8a5300931a7dd3163e8358f5c

+ 14 - 0
README.md

@@ -0,0 +1,14 @@
+# Microstimulation V1 and V4 of monkey cortex    
+
+### Description    
+This data and analysis produces the figures for the study published as the paper mentioned below. In this study we used electrical microstimulation to reveal distinct signatures of feedforward and feedback connections in the visual cortex of monkeys.       
+
+- Stimulation of V1 and recording in V1 (local) or V4 (feedforward) using Utah arrays.   
+- Stimulation of V4 and recording in V4 (local) or V1 (feedback).
+- Stimulation during a visual Figure-Ground task to investigate interaction with the visual response.     
+
+### Paper    
+[Klink, P.C.*, Dagnino, B.*, Gariel-Mathis, M-A.*, & Roelfsema, P.R. (2017). Distinct feedforward and feedback effects of microstimulation in visual cortex reveals neural mechanisms of texture-segregation. Neuron. 95(1), 209–220.e3.](http://dx.doi.org/10.1016/j.neuron.2017.05.033)    
+
+### How to use    
+The `main.m` script in the `SCRIPTS` folder takes you through the generation of all figures step-by-step.    

+ 439 - 0
SCRIPTS/FUNCTIONS/FB_FIGURES.m

@@ -0,0 +1,439 @@
+%% Generate the FEEDBACK MS figure panels ===============================
+fprintf('== GENERATING FEEDBACK MS EFFECT FIGURES ==================\n')
+
+% Effect Windows
+EffWin.V1toV4.Exc = [0 0.050];
+EffWin.V1toV4.Sup = [0.050 0.120];
+EffWin.V4toV1.Exc = [0 0.030];
+EffWin.V4toV1.Sup = [0.030 0.150];
+
+% FEEDBACK V4 to V1 
+EffectWindow.exc = EffWin.V4toV1.Exc;
+EffectWindow.sup = EffWin.V4toV1.Sup;
+
+fprintf(['Calculating V1 effect sizes in the following post-stimulation windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+V4MS = preProcessV4MS(V4MS,EffectWindow);
+
+%% FIGURE 6C - EXAMPLE UNIT V1 ==========================================
+fprintf('\n -- FIGURE 6C ----------\n');
+
+INDS = find(V4MS.RFDATA(:,5)>-1);
+indCH = 36;
+
+V4MS.META.S = 1;
+soa = 3;
+S = 8;
+
+BL_EX = smooth(V4MS.CLEAN.UNITS(:,INDS(indCH),1),S );
+MAX = nanmax(BL_EX); BL_EX = BL_EX/MAX;
+MS_EX = smooth(V4MS.CLEAN.UNITS(:,INDS(indCH),soa+1),S )/MAX;
+FSZ = 12;
+
+figure (44);clf; hold all;
+set(gca,'FontSize',FSZ)
+xlim([-0.1 0.35])
+ylim([-0.15 1.05])
+
+YL = ylim;p = patch([0.15 0.15 0.15+0.025 0.15+0.025],...
+    [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none',...
+    'FaceColor',[230 220 110]/255);
+hms = plot(V4MS.TIME,smooth(MS_EX,1),'Color',...
+    V4MS.META.COLS(soa+1,:),'LineWidth',2);
+hbl = plot(V4MS.TIME,smooth(BL_EX,1),'Color',...
+    0*V4MS.META.COLS(1,:),'LineWidth',2);
+
+legend([hbl hms],{'no MS' 'MS'})
+xlabel('Time [s]'); ylabel('MUA')
+
+print_figure('figure6C',[0 0 7 7],fullfile(fld.figs,'FIG_6'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE 6B - Make RF figure FB ========================================
+fprintf('\n -- FIGURE 6B ----------\n');
+load(fullfile(fld.data,'MAPPINGS','RF_B.mat'));
+
+figure(17);
+set(gca,'FontSize',FSZ)
+V4Lims=[0 9; -9 0];
+NV1RFs=[3]; % Say how many V1 RF there are.
+v1ch = 3; % Say which one do you want to plot
+% (if you want only RF 1 and 3 for example you can use v1ch=[1 3] )
+NV4CH=19; % Set the V4 channel that you want to plot.
+YTicks=[-9:2:0];
+XTicks=[0:2:9];
+[X,Y]=meshgrid(V4Lims(1,1):V4Lims(1,2),V4Lims(2,1):V4Lims(2,2));
+
+ST=0.01;
+[XI,YI]=meshgrid([V4Lims(1,1):ST:V4Lims(1,2)],[V4Lims(2,1):ST:V4Lims(2,2)]);
+
+SM=3; count=0;
+
+wh=[0.5 0.5];
+POS=[0.5 1; 1 1; 0.5 0.5; 1 0.5];
+count=count+1;
+
+TEMP=squeeze(RESPMATV4(NV4CH,:,:));
+if SM~=0
+    TEMP3=TEMP;
+    for j=1:size(TEMP,1)
+        TEMP3(j,:)=smooth(TEMP(j,:),SM);
+    end
+    for i=1:size(TEMP3,2)
+        TEMP3(:,i)=smooth(TEMP3(:,i),SM);
+    end
+else
+    TEMP3=TEMP;
+end
+
+
+Z=interp2(X,Y,TEMP3,XI,YI);
+
+colormap('default')
+imagesc(V4Lims(1,:),V4Lims(2,:),Z/max(max(Z)));
+set(gca,'YDir','normal')
+hold on
+axis('square')
+COLORS=[159/255, 29/255, 53/255; 0 128/255 0; ...
+    125/255, 249/255, 1; 244/255, 196/255, 48/255];
+for v1=v1ch
+    TEMP=DATAV1(v1);
+    
+    DAT=TEMP.DAT;
+    sampf=TEMP.Sampf;
+    MP=TEMP.MP;
+    DegperS=TEMP.DegperS;
+    OFF.rho=TEMP.RFPecc;
+    OFF.angle=TEMP.RFPangle;
+    
+    RF_INFO(v1)= RFpos(DAT, sampf, MP, DegperS, OFF);
+    
+    Mid=RF_INFO(v1).Mid;
+    WH=RF_INFO(v1).WH;
+    clr=RF_INFO(v1).clr;
+    Ic=RF_INFO(v1).Ic;
+    if v1==1;channs=[2 3 4 7 10 11 12 14];
+    elseif v1==2;channs=[1 2 3 4 6 11 12 14 15];
+    elseif v1==3;channs=[2];
+    end
+    for chan = channs
+        M = [Mid.x(chan) Mid.y(chan)];
+        P = patch([Mid.x(chan)-WH(chan).w2 Mid.x(chan)+WH(chan).w2 Mid.x(chan)+WH(chan).w2 Mid.x(chan)-WH(chan).w2], ...
+            [Mid.y(chan)-WH(chan).h2 Mid.y(chan)-WH(chan).h2 Mid.y(chan)+WH(chan).h2 Mid.y(chan)+WH(chan).h2],COLORS(v1,:), ...
+            'EdgeColor', 'w','LineWidth',4); % COLORS(v1,1:3)
+        set(P,'FaceColor','none')
+    end
+end
+
+plot(xlim,[0 0],'w:')
+plot([0 0], ylim,'w:')
+scatter(0,0,[],[0 0 0],'Filled')
+set(gca,'XAxisLocation','top')
+set(gca,'Color',[0 0 1])
+xlabel('Horizontal Position [deg]')
+ylabel('Vertical Position [deg]')
+
+print_figure('figure6B',[0 0 7 7],fullfile(fld.figs,'FIG_6'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE 4C - RF overlap vs Supp effect ================================ 
+fprintf('\n -- FIGURE 4C ----------\n');
+
+OVER = V4MS.RFDATA(:,5);
+EFFE  = 50*V4MS.EFFECT(3,:);
+AMP = V4MS.RFDATA(:,12);
+
+OVER_SIG = OVER(logical(V4MS.CLEAN.UNITSIND) & ~isnan(OVER));
+EFFE_SIG = EFFE(logical(V4MS.CLEAN.UNITSIND) & ~isnan(OVER));
+AMP_SIG  = AMP(logical(V4MS.CLEAN.UNITSIND) & ~isnan(OVER));
+
+OVER = OVER(~isnan(OVER));
+EFFE = EFFE(~isnan(OVER));
+AMP = AMP(~isnan(OVER));
+
+eff = EFFE./AMP';
+over = OVER;
+
+iNAN = isnan(eff);
+eff(iNAN) = [];
+over(iNAN) = [];
+X = [ones(length(eff),1) over];
+y = eff';
+[b,bint,r,rint,stats] = regress(y,X);
+
+[r,n,p,t] = regressionTTest(y,stats);
+    disp(['R = ' num2str(r)])
+    disp(['N = ' num2str(n)])
+    disp(['P = ' num2str(p)])
+    disp(['T = ' num2str(t)])
+
+figure(100);clf;hold all
+set(gca,'FontSize',10)
+scatter(OVER,EFFE./AMP',60,[0.75 0.75 0.9],'filled','LineWidth',1)
+scatter(OVER_SIG,EFFE_SIG./AMP_SIG',60,V4MS.META.COLS(4,:),'filled','LineWidth',1)
+plot([0.1 0.95],b(2)*[0.15 0.99]+b(1),'Color',0*V4MS.META.COLS(2,:))
+xlim([0 1])
+ylabel('Effect Size')
+set(gca,'XTick',[0 0.5 1])
+
+plot(xlim,[0 0],'k:','LineWidth',2)
+xlabel('RFs Overlap')
+print_figure('figure4C',[0 0 7 7],fullfile(fld.figs,'FIG_4'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE 6D SOA both monkeys ===========================================
+fprintf('\n -- FIGURE 6D ----------\n');
+
+S = 10;
+SS = [-0.02 0.05 .15];
+figure;clf;
+for soa = 1:3
+    subplot(1,3,soa);hold all;
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35]); ylim([-0.15 1.05]); YL = ylim;
+    p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+        'EdgeColor','none','FaceColor',[230 220 110]/255);
+    hms = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,soa+1)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),S),...
+        'Color',V4MS.META.COLS(soa+1,:), 'LineWidth',1);
+    hbl = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),...
+        'Color',0*V4MS.META.COLS(1,:),'LineWidth',1);
+    legend([hbl hms],{'no MS' 'MS'})
+    xlabel('Time [s]')
+    title(['SOA ' num2str(SS(soa)*1000) ' ms']);
+end
+fprintf(['N = ' num2str(sum(V4MS.CLEAN.UNITSIND)) '\n']);
+
+print_figure('figure6D',[0 0 21 7],fullfile(fld.figs,'FIG_6'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE S3B SOA per MONKEY ============================================
+fprintf('\n -- SUPP FIGURE 3B ----------\n');
+
+MS = {'B' 'C'};
+for m = 1:2
+    S = 10;
+    SS = [-0.02 0.05 .15];  
+    temp = nanmean(nanmean(V4MS.CLEAN.UNITS(:,strcmp(V4MS.MONKEY,MS{m}),:),3),1);
+    fprintf(['Monkey ' MS{m} ', n = ' num2str(sum(~isnan(temp))) '\n'])  
+    AVS = squeeze(nanmean(V4MS.CLEAN.UNITS(:,strcmp(V4MS.MONKEY,MS{m}),:),2));
+    
+    figure (m+400*m);clf;
+    for soa = 1:3
+        subplot(1,3,soa);hold all;
+        set(gca,'FontSize',FSZ)
+        xlim([-0.1 0.35])
+        ylim([-0.2 1.05])
+        YL = ylim;p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+            [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none',...
+            'FaceColor',[230 220 110]/255);
+        hms = plot(V4MS.TIME,smooth(AVS(:,soa+1)/nanmax(smooth(AVS(:,1),S)),S),...
+            'Color',V4MS.META.COLS(soa+1,:), 'LineWidth',1);
+        hbl = plot(V4MS.TIME,smooth(AVS(:,1),S)/nanmax(smooth(AVS(:,1),S)),...
+            'Color',V4MS.META.COLS(1,:)*0,'LineWidth',1);
+        
+        legend([hbl hms],{'no MS' 'MS'})
+        xlabel('Time [s]')
+    end
+    print_figure(['suppfigure3B_Monkey' MS{m}],[0 0 21 7],...
+        fullfile(fld.figs,'SUPPFIG_3'),save_figs);
+    cd(fld.scripts);
+end
+
+%% FIGURE 6E - Diff MUA by SOA, triggered on MS ========================= 
+fprintf('\n -- FIGURE 6E ----------\n');
+
+figure (8);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.15 0.06])
+YL = ylim;p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],...
+    0.8*[1 1 1],'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10;
+SAOS = [-0.02 0.05 0.15];
+hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V4MS.TIME-SAOS(soa),...
+        smooth(-V4MS.CLEAN.AVE(:,1)+V4MS.CLEAN.AVE(:,soa+1),S)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),...
+        'Color',V4MS.META.COLS(soa+1,:),'LineWidth',1);
+    xlim([-0.1 0.2])
+end
+
+plot(xlim,[0 0],'k:')
+set(gca,'YTick',[-0.1:0.05:0.05]);
+set(gca,'XTick',[-0.1:0.1:0.1]);
+legend(hds,{'-20ms' '50ms' '150ms'},'Location','SouthWest')
+ylabel('MS - no MS');
+xlabel('Time [s]')
+print_figure('figure6E',[0 0 13 5.5],fullfile(fld.figs,'FIG_6'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE S3C - Supressive effect per monkey ============================
+fprintf('\n -- SUPP FIGURE 3C ----------\n');
+
+for m = 1:2
+    figure (856+m);clf;hold all;
+    set(gca,'FontSize',FSZ)
+    ylim([-0.2 0.1])
+    YL = ylim;p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],...
+        0.8*[1 1 1],'EdgeColor','none','FaceColor',[230 220 110]/255);
+    S = 10;
+    SAOS = [-0.02 0.05 0.15];
+    
+    AVS = squeeze(nanmean(V4MS.CLEAN.UNITS(:,strcmp(V4MS.MONKEY,MS{m}),:),2));
+    
+    hds = [];
+    for soa = 1:3
+        hds(end+1) = plot(V4MS.TIME-SAOS(soa),smooth(-AVS(:,1)+AVS(:,soa+1),S)/...
+            nanmax(smooth(AVS(:,1),S)),'Color',V4MS.META.COLS(soa+1,:),'LineWidth',1);
+        xlim([-0.1 0.2])
+    end
+
+    plot(xlim,[0 0],'k:')
+    legend(hds,{'-20ms' '50ms' '150ms'},'Location','SouthWest')
+    ylabel('MS - no MS'); xlabel('Time [s]');
+    print_figure(['suppfigure3C_Monkey' MS{m}],[0 0 7 7],...
+        fullfile(fld.figs,'SUPPFIG_3'),save_figs);
+    cd(fld.scripts);
+end
+
+%% FIGURE 6F - Average Effect Sizes per SOA =============================
+fprintf('\n -- FIGURE 6F ----------\n');
+
+ANOVA_DATA= [];ANOVA_DATA2= [];
+OVER = V4MS.RFDATA(:,5);
+
+figure(103);clf;hold all
+
+subplot(1,2,2);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V4MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));;
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V4MS.META.COLS(soa+1,:))
+    
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([-0.07 0.032])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+% plot(xlim,[0 0],'k:','LineWidth',2)
+xlabel('SOA [ms]')
+title('Suppression')
+
+subplot(1,2,1);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V4MS.EXCIT_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));;
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V4MS.META.COLS(soa+1,:))
+    
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.07 0.032])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+% plot(xlim,[0 0],'k:','LineWidth',2)
+xlabel('SOA [ms]')
+title('Excitation')
+
+print_figure('figure6F',[0 0 7 7],fullfile(fld.figs,'FIG_6'),save_figs)
+cd(fld.scripts);
+
+%% STATS for FiG 6F =====================================================
+fprintf('Statistics for FIG 6F\n');
+
+fprintf('- Excitation -\n');
+anova_data2 = ANOVA_DATA2;
+anova_data2(isnan(ANOVA_DATA2(:,1)),:) = [];
+[P2,ANOVATAB2,STATS2] = anova1(anova_data2);
+[c2,m2,h2,names2] = multcompare(STATS2,'Alpha',10^-15,'CType','tukey-kramer');
+
+for s=1:3
+    [h_soa{s},p_soa{s}] = ttest(anova_data2(:,s));
+    fprintf(['SOA ' num2str(c2(s,1)) ' vs ' num2str(c2(s,2)) ': p = ' ...
+        num2str(c2(s,6)) '\n']);
+end
+
+fprintf('- Suppression -\n');
+anova_data = ANOVA_DATA;
+anova_data(isnan(ANOVA_DATA(:,1)),:) = [];
+[P,ANOVATAB,STATS] = anova1(anova_data);
+[c,m,h,names] = multcompare(STATS,'Alpha',10^-15,'CType','tukey-kramer');
+
+for i=1:3
+    fprintf(['SOA ' num2str(c(i,1)) ' vs ' num2str(c(i,2)) ': p = ' ...
+        num2str(c(i,6)) '\n']);
+end
+
+%% FIGURE 4D - Suppression effect size vs MUA ===========================
+fprintf('\n -- FIGURE 4D ----------\n');
+
+S = 10; SS = [-0.05 0.05 .15];
+
+% Compute activity during blank trials.
+BASES = nan(size(V4MS.CLEAN.UNITS,2),3);
+for soa = 1:3
+    indT = V4MS.TIME > (SS(soa)+0.025) & V4MS.TIME < (SS(soa)+0.125);
+    BASES(:,soa) = squeeze(nanmean(V4MS.UNITS(indT,:,1),1));
+end
+
+EFFS = nan(size(V4MS.CLEAN.UNITS,2),3);
+for soa = 1:3
+    EFFE  = V4MS.EFFECT(soa,:);
+    EFFS(:,soa) = EFFE;
+end
+
+figure(105);clf;hold on
+set(gca,'FontSize',FSZ)
+xlim([-0.45 0.45])
+
+for soa = 3 % only the 150 ms SOA
+    scatter(BASES(:,soa),EFFS(:,soa),60,[0.75 0.75 0.9],'filled','LineWidth',1),
+    scatter(BASES(logical(V4MS.CLEAN.UNITSIND),soa),...
+        EFFS(logical(V4MS.CLEAN.UNITSIND),soa),60,...
+        V4MS.META.COLS(soa+1,:),'filled','LineWidth',1);
+    
+    % compute regressions
+    indM = logical(V4MS.CLEAN.UNITSIND);
+    eff = EFFS(indM,soa);
+    over = BASES(indM,soa);
+    
+    iNAN = isnan(mean([eff over],2));
+    
+    eff(iNAN) = [];
+    over(iNAN) = [];
+    
+    X = [ones(length(eff),1) over];
+    y = eff';
+    [b,bint,r,rint,stats] = regress(y',X);
+    
+    [r,n,p,t] = regressionTTest(y,stats);
+    disp(['R = ' num2str(r)])
+    disp(['N = ' num2str(n)])
+    disp(['P = ' num2str(p)])
+    disp(['T = ' num2str(t)])
+end
+h = lsline;
+xlim([-0.45 0.4])
+set(h(1),'Color','k','LineStyle','--')
+set(h(2),'LineStyle','none');
+xlabel('Average MUA')
+ylabel('Effect Size')
+
+print_figure('figure4D' ,[0 0 7 7],fullfile(fld.figs,'FIG_4'),save_figs);
+cd(fld.scripts);

+ 491 - 0
SCRIPTS/FUNCTIONS/FF_FIGURES.m

@@ -0,0 +1,491 @@
+%% Generate the FEEDFORWARD MS figure panels ============================
+fprintf('== GENERATING FEEDFORWARD MS EFFECT FIGURES ==================\n')
+
+% Effect Windows
+EffWin.V1toV4.Exc = [0 0.050];
+EffWin.V1toV4.Sup = [0.050 0.120];
+EffWin.V4toV1.Exc = [0 0.030];
+EffWin.V4toV1.Sup = [0.030 0.150];
+
+% FEEDFORWARD V1 to V4
+EffectWindow.exc = EffWin.V1toV4.Exc;
+EffectWindow.sup = EffWin.V1toV4.Sup;
+
+fprintf(['Calculating V4 effect sizes in the following post-stimulation windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+V1MS = preProcessV1MS(V1MS,EffectWindow);
+
+%% FIGURE 3D - Example unit V1 ==========================================
+fprintf('\n -- FIGURE 3D ----------\n');
+
+% Set unit to plot as example. 
+INDS = find(V1MS.RFDATA(:,5)>-1);
+indCH = 31; soa = 1; S = 8;
+
+% Normalized based on peak of blank (no MS) average. 
+BL_EX = smooth(V1MS.CLEAN.UNITS(:,INDS(indCH),1),S );
+MAX = nanmax(BL_EX); BL_EX = BL_EX/MAX;
+MS_EX = smooth(V1MS.CLEAN.UNITS(:,INDS(indCH),soa+1),S )/MAX;
+
+FSZ = 12;
+figure (44);clf; hold all;
+set(gca,'FontSize',FSZ)
+xlim([-0.1 0.35]); ylim([-0.15 1.6]); YL = ylim;
+p = patch([-0.05 -0.05 -0.05+0.025 -0.05+0.025],[YL(1) ...
+    YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none','FaceColor',[230 220 110]/255);
+hms = plot(V1MS.TIME,smooth(MS_EX,1),'Color',V1MS.META.COLS(soa+1,:),'LineWidth',2);
+hbl = plot(V1MS.TIME,smooth(BL_EX,1),'Color',V1MS.META.COLS(1,:)*0,'LineWidth',2);
+legend([hbl hms],{'MS' 'BL'})
+xlabel('Time [s]'); ylabel('MUA');
+print_figure('figure3D',[0 0 7 7],fullfile(fld.figs,'FIG_3'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE 3B - Make RF figure FF ========================================
+fprintf('\n -- FIGURE 3B ----------\n');
+load(fullfile(fld.data,'MAPPINGS','RF_B.mat'));
+
+% Compute and plot V4 RF.
+figure(18);
+set(gca,'FontSize',FSZ)
+V4Lims=[0 9; -9 0];
+NV1RFs=[3]; % Say how many V1 RF there are.
+v1ch = 3; % Say which one do you want to plot 
+% (if you want only RF 1 and 3 for example you can use v1ch=[1 3] )
+NV4CH=27; % Set the V4 channel that you want to plot.
+YTicks=[-9:2:0];
+XTicks=[0:2:9];
+
+[X,Y]=meshgrid(V4Lims(1,1):V4Lims(1,2),V4Lims(2,1):V4Lims(2,2));
+ST=0.01;
+[XI,YI]=meshgrid([V4Lims(1,1):ST:V4Lims(1,2)],...
+    [V4Lims(2,1):ST:V4Lims(2,2)]);
+SM=3; count=0;
+wh=[0.5 0.5]; POS=[0.5 1; 1 1; 0.5 0.5; 1 0.5];
+count=count+1;
+
+TEMP=squeeze(RESPMATV4(NV4CH,:,:));
+if SM~=0
+    TEMP3=TEMP;
+    for j=1:size(TEMP,1)
+        TEMP3(j,:)=smooth(TEMP(j,:),SM);
+    end
+    for i=1:size(TEMP3,2)
+        TEMP3(:,i)=smooth(TEMP3(:,i),SM);
+    end
+else
+    TEMP3=TEMP;
+end
+
+Z=interp2(X,Y,TEMP3,XI,YI);
+colormap('default')
+imagesc(V4Lims(1,:),V4Lims(2,:),Z/max(max(Z)));
+set(gca,'YDir','normal')
+hold on; axis('square')
+
+% Plot v1 channel RF.
+COLORS=[159/255, 29/255, 53/255; 0 128/255 0; ...
+    125/255, 249/255, 1; 244/255, 196/255, 48/255];
+for v1=v1ch
+    TEMP=DATAV1(v1);
+    
+    DAT=TEMP.DAT;
+    sampf=TEMP.Sampf;
+    MP=TEMP.MP;
+    DegperS=TEMP.DegperS;
+    OFF.rho=TEMP.RFPecc;
+    OFF.angle=TEMP.RFPangle;
+    
+    RF_INFO(v1)= RFpos(DAT, sampf, MP, DegperS, OFF);
+    
+    Mid=RF_INFO(v1).Mid;
+    WH=RF_INFO(v1).WH;
+    clr=RF_INFO(v1).clr;
+    Ic=RF_INFO(v1).Ic;
+    if v1==1;channs=[14];
+    elseif v1==2;channs=[1 2 3 4 6 11 12 14 15];
+    elseif v1==3;channs=[2];
+    end
+    for chan = channs
+        M = [Mid.x(chan) Mid.y(chan)];
+        P = patch([Mid.x(chan)-WH(chan).w2 Mid.x(chan)+WH(chan).w2 ...
+            Mid.x(chan)+WH(chan).w2 Mid.x(chan)-WH(chan).w2], ...
+            [Mid.y(chan)-WH(chan).h2 Mid.y(chan)-WH(chan).h2 ...
+            Mid.y(chan)+WH(chan).h2 Mid.y(chan)+WH(chan).h2],COLORS(v1,:), ...
+            'EdgeColor', 'w','LineWidth',4); 
+        set(P,'FaceColor','none')
+    end
+end
+
+set(gca,'XAxisLocation','top'); set(gca,'Color',[0 0 1]);
+xlabel('Horizontal Position [deg]'); ylabel('Vertical Position [deg]');
+
+print_figure('figure3B',[0 0 7 7],fullfile(fld.figs,'FIG_3'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE 4A - Test Overlap RF ==========================================
+fprintf('\n -- FIGURE 4A ----------\n');
+OVER = V1MS.RFDATA(:,5); % Overlapp between V1 anv V4 RFs. 
+EFFE  = 50*V1MS.EFFECT(1,:); % Effect size for ALL channels. 
+AMP = V1MS.RFDATA(:,8); % MS current amplitude.
+
+% Same as before but only for unit with a significant EFFECT and there is
+% RF data for both V1 and V4 electrode.
+OVER_SIG = OVER(logical(V1MS.CLEAN.UNITSIND) & ~isnan(OVER));
+EFFE_SIG = EFFE(logical(V1MS.CLEAN.UNITSIND) & ~isnan(OVER));
+AMP_SIG  = AMP(logical(V1MS.CLEAN.UNITSIND) & ~isnan(OVER));
+
+% Compute correlation for current normalized effect size. 
+eff = EFFE_SIG./AMP_SIG';
+over = OVER_SIG;
+iNAN = isnan(eff);
+eff(iNAN) = [];
+over(iNAN) = [];
+X = [ones(length(eff),1) over];
+y = eff';
+[b,bint,r,rint,stats] = regress(y,X);
+
+% Same as before with both significant and non significant units. 
+OVER = OVER(~isnan(OVER));
+EFFE = EFFE(~isnan(OVER));
+AMP = AMP(~isnan(OVER));
+eff = EFFE./AMP';
+over = OVER;
+iNAN = isnan(eff);
+eff(iNAN) = [];
+over(iNAN) = [];
+X = [ones(length(eff),1) over];
+y = eff';
+[b,bint,r,rint,stats] = regress(y,X);
+
+%Significante of the correlations. 
+fprintf('\n-- Regression RF vs Exc Effect --\n');
+[r,n,p,t] = regressionTTest(y,stats);
+    disp(['R = ' num2str(r)])
+    disp(['N = ' num2str(n)])
+    disp(['P = ' num2str(p)])
+    disp(['T = ' num2str(t)])
+
+figure(132);clf;hold all
+set(gca,'FontSize',FSZ)
+scatter(OVER,EFFE./AMP',60,[0.75 0.75 0.9],'filled','LineWidth',1)
+scatter(OVER_SIG,EFFE_SIG./AMP_SIG',60,V1MS.META.COLS(4,:),...
+    'filled','LineWidth',1)
+
+xlim([0 1]); ylim([-0.01 0.055]*50);
+plot([0.1 0.97],b(2)*[0.15 0.99]+b(1),'Color',0*V1MS.META.COLS(2,:))
+ylabel('Effect Size'); plot(xlim,[0 0],'k:','LineWidth',2);
+xlabel('RFs Overlap');
+print_figure('figure4A',[0 0 7 7],fullfile(fld.figs,'FIG_4'),save_figs)
+cd(fld.scripts);
+
+%% FIGURE S3A - SOA per Monkey ==========================================
+fprintf('\n -- SUPP FIGURE 3A ----------\n');
+
+S = 10; SS = [-0.05 0.05 .15];
+monkeys = {'B' 'C'};
+for M = 1:2
+    figure (800+M);clf;
+    iM = strcmp(V1MS.MONKEY,monkeys{M});
+    temp = nanmean(nanmean(V1MS.CLEAN.UNITS(:,iM,:),3),1);
+    ncount=sum(~isnan(temp));
+    fprintf(['Monkey ' monkeys{M} ', n = ' num2str(ncount) '\n']);
+    AVE =  squeeze(nanmean(V1MS.CLEAN.UNITS(:,iM,:),2));
+    
+    for soa = 1:3
+        subplot(1,3,soa);hold all;
+        set(gca,'FontSize',FSZ)
+        xlim([-0.1 0.35])
+        if strcmp(monkeys{M},'C')
+            ylim([-1 3.3])
+        else
+            ylim([-0.2 1.7])
+        end
+        YL = ylim;
+        p = patch([SS(soa) SS(soa) SS(soa)+0.025 ...
+            SS(soa)+0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+            'EdgeColor','none','FaceColor',[230 220 110]/255);
+        hms = plot(V1MS.TIME,smooth(AVE(:,soa+1)/nanmax(smooth(AVE(:,1),S)),S),...
+            'Color',V1MS.META.COLS(soa+1,:), 'LineWidth',2);
+        hbl = plot(V1MS.TIME,smooth(AVE(:,1),S)/nanmax(smooth(AVE(:,1),S)),...
+            'Color',V1MS.META.COLS(1,:)*0,'LineWidth',2);
+        legend([hbl hms],{'no MS' 'MS'}); xlabel('Time [s]');
+        title(['SOA ' num2str(SS(soa)*1000) ' ms']);
+    end
+    print_figure(['suppfigure3A_Monkey' monkeys{M}],[0 0 7 7],...
+        fullfile(fld.figs,'SUPPFIG_3'),save_figs);
+    cd(fld.scripts);
+end
+
+%% FIGURE 3E - SOA both monkeys =========================================
+fprintf('\n -- FIGURE 3E ----------\n');
+
+S = 10; SS = [-0.05 0.05 .15];
+figure(55);clf;
+for soa = 1:3
+    subplot(1,3,soa);hold all;
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.7 3.4])
+    YL = ylim; 
+    p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none','FaceColor',...
+        [230 220 110]/255);
+    hms = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,soa+1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),S),...
+        'Color',V1MS.META.COLS(soa+1,:), 'LineWidth',2);
+    hbl = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),...
+        'Color',V1MS.META.COLS(1,:)*0,'LineWidth',2);
+    legend([hbl hms],{'no MS' 'MS'})
+    title(['SOA ' num2str(SS(soa)*1000) ' ms']);
+    xlabel('Time [s]')  
+end
+print_figure('figure3E' ,[0 0 7 7],fullfile(fld.figs,'FIG_3'),save_figs);
+cd(fld.scripts);
+
+%% FIGURE 3F - Difference for every SOA locked to MS ====================
+fprintf('\n -- FIGURE 3F ----------\n');
+
+figure(8);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.8 3.45])
+YL = ylim;
+p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+    'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10; SAOS = [-0.05 0.05 0.15];
+hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V1MS.TIME-SAOS(soa),...
+        smooth(-V1MS.CLEAN.AVE(:,1)+V1MS.CLEAN.AVE(:,soa+1),S)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),...
+        'Color',V1MS.META.COLS(soa+1,:),'LineWidth',2);
+    xlim([-0.1 0.2])
+end
+
+plot(xlim,[0 0],'k:')
+legend(hds,{'-50ms' '50ms' '150ms'},'Location','NorthEast')
+xlabel('Time [s]')
+print_figure('figure3F' ,[0 0 7 7],fullfile(fld.figs,'FIG_3'),save_figs);
+    cd(fld.scripts);
+
+%% FIGURE S4B - 25% of electrodes with smalles effect size at SOA 2 =====
+fprintf('\n -- SUPP FIGURE 4B ----------\n');
+
+eff = V1MS.CLEAN.EFFECT(2,:)';
+amp = V1MS.RFDATA(:,8);
+units = V1MS.CLEAN.UNITS;
+
+iNotNan = ~isnan(eff) & ~isnan(amp);
+
+eff = eff(iNotNan);amp = amp(iNotNan);units = units(:,iNotNan,:);
+[v,indSort] = sort(abs(eff));
+
+i25percent = 1:round(0.25*length(amp));
+
+avUnits   = squeeze(nanmean(units,2));
+av25units = squeeze(nanmean(units(:,indSort(i25percent),:),2));
+
+subUnits = avUnits(:,2:4) - repmat(avUnits(:,1),1,3);
+sub25units = av25units(:,2:4) - repmat(av25units(:,1),1,3);
+
+figure(856);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.6 1.8])
+YL = ylim;p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],...
+    0.8*[1 1 1],'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 3;
+SAOS = [-0.05 0.05 0.15];
+hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V1MS.TIME-SAOS(soa),...
+        smooth(-av25units(:,1)+av25units(:,soa+1),S)/...
+        nanmax(smooth(av25units(:,1),S)),'Color',...
+        V1MS.META.COLS(soa+1,:),'LineWidth',2);
+    xlim([-0.1 0.3])
+end
+
+plot(xlim,[0 0],'k:')
+legend(hds,{'-50ms' '50ms' '150ms'},'Location','NorthEast')
+ylabel('MS - BL'); xlabel('Time [s]')
+
+print_figure('suppfigure4B' ,[0 0 7 7],...
+    fullfile(fld.figs,'SUPPFIG_4'),save_figs);
+    cd(fld.scripts);
+
+%% FIGURE S4A - MUA for 25% electrodes with smallest effect at SOA 2 ====
+fprintf('\n -- SUPP FIGURE 4A ----------\n');
+
+S = 10; SS = [-0.05 0.05 .15];
+figure (soa+3737);clf;
+for soa = 1:3
+    subplot(1,3,soa);hold all;
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.3 1.7])
+    YL = ylim;p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+        'EdgeColor','none','FaceColor',[230 220 110]/255);
+    hms = plot(V1MS.TIME,smooth(av25units(:,soa+1)/...
+        nanmax(smooth(av25units(:,1),S)),S),'Color',...
+        V1MS.META.COLS(soa+1,:), 'LineWidth',2);
+    hbl = plot(V1MS.TIME,smooth(av25units(:,1),S)/...
+        nanmax(smooth(av25units(:,1),S)),'Color',...
+        V1MS.META.COLS(1,:)*0,'LineWidth',2);
+    legend([hbl hms],{'no MS' 'MS'})
+    xlabel('Time [s]')
+    title(['SOA ' num2str(SS(soa)*1000) ' ms']);
+end
+print_figure('suppfigure4A' ,[0 0 7 7],...
+    fullfile(fld.figs,'SUPPFIG_4'),save_figs);
+cd(fld.scripts);
+
+%% FIGURE S4C - Scatter plots for these conditions ======================
+fprintf('\n -- SUPP FIGURE 4C ----------\n');
+
+EFF = V1MS.CLEAN.EFFECT(:,iNotNan);
+SS = [-0.05 0.05 .15];
+COMBS = [1 2; 1 3; 2 3];
+LIMS = [-0.3 1.5];
+figure(178);clf;
+plotCount = 0;
+for comb = [1 3]
+    plotCount = plotCount + 1;
+    subplot(1,2,plotCount)
+    hold all;
+    scatter(V1MS.CLEAN.EFFECT(COMBS(comb,1),indSort((i25percent+1):end)),...
+        V1MS.CLEAN.EFFECT(COMBS(comb,2),...
+        indSort((i25percent+1):end)),10,[0 0 0],'filled');
+    scatter(EFF(COMBS(comb,1),indSort(i25percent)),EFF(COMBS(comb,2),...
+        indSort(i25percent)),10,[0.8 0.2 0.5],'filled');
+    plot(LIMS,LIMS,':k');
+    xlim(LIMS);ylim(LIMS);
+    plot([0 0],ylim,':','Color',0.5*[1 1 1])
+    plot(xlim,[0 0],':','Color',0.5*[1 1 1])
+    xlabel(['SOA ' num2str(1000*SS(COMBS(comb,1))) ' ms']);
+    ylabel(['SOA ' num2str(1000*SS(COMBS(comb,2))) ' ms']);
+    axis square
+end
+print_figure('suppfigure4C' ,[0 0 7 7],...
+    fullfile(fld.figs,'SUPPFIG_4'),save_figs);
+cd(fld.scripts);
+
+%% FIGURE 3G - Average Effect Size per SOA ==============================
+fprintf('\n -- SUPP FIGURE 3G ----------\n');
+
+ANOVA_DATA = [];ANOVA_DATA2 = [];
+
+figure(103);clf;hold all
+subplot(1,2,1);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V1MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(logical(V1MS.CLEAN.UNITSIND))/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([0 1.65]); xlim([0.5 3.5]);
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference'); xlabel('SOA [ms]');
+title('Excitation');
+
+subplot(1,2,2);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V1MS.SUPPR_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(logical(V1MS.CLEAN.UNITSIND))/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.55 0.05])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference');xlabel('SOA [ms]');
+title('Suppression');
+
+print_figure('figure3G' ,[0 0 7 7],fullfile(fld.figs,'FIG_3'),save_figs);
+cd(fld.scripts);
+
+%% STATS for FIG 3G =====================================================
+fprintf('Statistics for FIG 3G\n');
+
+fprintf('- Excitation -\n');
+anova_data = ANOVA_DATA;
+anova_data(isnan(ANOVA_DATA(:,1)),:) = [];
+[P,ANOVATAB,STATS] = anova1(anova_data);
+[c,m,h,names] = multcompare(STATS,'Alpha',10^-6,'CType','tukey-kramer');
+for i=1:3
+    fprintf(['SOA ' num2str(c(i,1)) ' vs ' num2str(c(i,2)) ': p = ' ...
+        num2str(c(i,6)) '\n']);
+end
+
+fprintf('- Suppression -\n');
+anova_data2 = ANOVA_DATA2;
+anova_data2(isnan(ANOVA_DATA2(:,1)),:) = [];
+[P2,ANOVATAB2,STATS2] = anova1(anova_data2);
+[c2,m2,h2,names2] = multcompare(STATS2,'Alpha',10^-6,'CType','tukey-kramer');
+for i=1:3
+    fprintf(['SOA ' num2str(c2(i,1)) ' vs ' num2str(c2(i,2)) ': p = ' ...
+        num2str(c2(i,6)) '\n']);
+end
+%% FIGURE 4B - Exc effect size vs MUA of Blank trials during stim. ======
+fprintf('\n -- FIGURE 4B ----------\n');
+S = 10; SS = [-0.05 0.05 .15];
+
+% Compute activity during blank trials.
+BASES = nan(size(V1MS.CLEAN.UNITS,2),3);
+for soa = 1:3
+    indT = V1MS.TIME > (SS(soa)+0) & V1MS.TIME < (SS(soa)+0.05);
+    BASES(:,soa) = squeeze(nanmean(V1MS.UNITS(indT,:,1),1));
+end
+
+% Get effect size per soa per unit
+EFFS = nan(size(V1MS.CLEAN.UNITS,2),3);
+for soa = 1:3
+    EFFE  = V1MS.EFFECT(soa,:);
+    EFFS(:,soa) = EFFE;
+end
+
+figure(104);clf;hold on
+set(gca,'FontSize',FSZ)
+
+for soa = 3 % only the 150 ms SOA
+    scatter(BASES(:,soa),EFFS(:,soa),60,[0.75 0.75 0.9],...
+        'filled','LineWidth',1),
+    scatter(BASES(logical(V1MS.CLEAN.UNITSIND),soa),...
+        EFFS(logical(V1MS.CLEAN.UNITSIND),soa),60,...
+        V1MS.META.COLS(soa+1,:),'filled','LineWidth',1);
+    % compute regressions
+    eff = EFFS(:,soa);
+    over = BASES(:,soa);
+    iNAN = isnan(eff);eff(iNAN) = [];over(iNAN) = [];
+    iNAN = isnan(over);eff(iNAN) = [];over(iNAN) = [];
+    X = [ones(length(eff),1) over];
+    y = eff;
+    [b,bint,r,rint,stats] = regress(y,X);
+    disp(['Regression stats for SOA #' num2str(soa)])
+    [r,n,p,t] = regressionTTest(y,stats);
+    disp(['R = ' num2str(r)])
+    disp(['N = ' num2str(n)])
+    disp(['P = ' num2str(p)])
+    disp(['T = ' num2str(t)])   
+end
+
+h = lsline;
+
+ylim([-0.3 1.4]); xlim([-0.28 0.62]);
+set(h(1),'Color','k','LineStyle','--')
+set(h(2),'LineStyle','none')
+xlabel('Average MUA'); ylabel('Effect Size')
+
+print_figure('figure4B' ,[0 0 7 7],fullfile(fld.figs,'FIG_4'),save_figs);
+cd(fld.scripts);

Filskillnaden har hållts tillbaka eftersom den är för stor
+ 1205 - 0
SCRIPTS/FUNCTIONS/FG_FIGURES.m


+ 983 - 0
SCRIPTS/FUNCTIONS/FG_spikes_ms5p.asv

@@ -0,0 +1,983 @@
+%% Population analysis of the SOA and Figure-Ground data SPIKES =========
+% ------------------------------------------------------------
+% Loads an overview table of data to potentially include, imports the
+% bandpass filtered data and saves it together in a population data file.
+% Once this has been done, it can also directly load this file and work
+% with that.
+
+% 5 pulse version !!
+
+% after collecting data, we can simply load the presaved population file
+presaved = true;
+MeanAlreadySubtracted = true;
+UseSelected = true;
+
+%% load info ============================================================
+% temp code to make table
+% V1FG = cell2table(V1FG_info(2:end,:),'VariableNames',V1FG_info(1,:));
+% s=[];
+% for i=1:size(V1FG.Monkey);
+%     if isempty(V1FG.Monkey{i})
+%         s=[s;i];
+%     end
+% end
+% V1FG(s,:)=[];
+
+% this file contains the info about individual files
+load(fullfile(fld.data,'V1V1_FG_5p.mat'));
+
+%% load data & get spikes ===============================================
+if ~presaved
+    curr_sel = 0;
+    for ff=1:length(V1FG.Day)
+        indstr = V1FG.indeces(ff);
+        sep = find(indstr{1}=='_'==1);
+        sel_files = ...
+            [str2double(indstr{1}(1:sep-1)) str2double(indstr{1}(sep+1:end))];
+        if curr_sel ~= sel_files(1) % only load files once
+            curr_sel=sel_files(1);
+
+            cd(MAT_PATH);
+            if MeanAlreadySubtracted
+                % << artefact removal in raw
+                cd(fullfile(fld.data,'BANDPASS','BP2','500to5000'));
+            else
+                % << first BP version (no artefact removal in raw)
+                cd(fullfile(fld.data,'BANDPASS','BP','500to5000'));
+            end
+
+            CHMap = [1:16;17:32];
+            CHi = [ones(1,16) ones(1,16).*2 ; 1:16 1:16];
+
+            for df=1:2
+                fprintf(['Loading ' filenames{sel_files(df)} '\n']);
+                load(filenames{sel_files(df)},'Data')
+                D(df)=Data; clear Data; %#ok<*SAGROW>
+                t_vis = D(df).Time;
+            end
+            cd(mpath)
+
+            MStime={'none',-50,50 150};
+            StimType={'Homogenous','Figure','Ground'};
+            typenum=0;
+
+            % categorize trials
+            for m=1:length(MStime)
+                for s=1:length(StimType)
+                    typenum=typenum+1;
+                    Trial(s,m).num = typenum;
+                    Trial(s,m).stim=StimType{s};
+                    Trial(s,m).ms = MStime{m};
+                    Trial(s,m).sel_trials = ...
+                        ~isnan(D(CHi(1,1)).Trials(:,3)) & ...
+                        D(CHi(1,1)).Trials(:,end)==typenum;
+                    Trial(s,m).i =(find(Trial(s,m).sel_trials==1))';
+                    TrialType{1,typenum} = StimType{s};
+                    TrialType{2,typenum} = MStime{m};
+                    TrialType{3,typenum} = Trial(s,m).i;
+                end
+            end
+        end
+        sC = V1FG.rec_channel(ff);
+        MUA = cell(12,2);
+        for tt =  1:size(TrialType,2)
+            sel_trials = TrialType{3,tt};
+            sel_trials_clean = [];
+
+            % check for artefacts
+            for t = sel_trials
+                sd = std(D(CHi(1,sC)).Signal(:,CHi(2,sC),t));
+                y = D(CHi(1,sC)).Signal(:,CHi(2,sC),t);
+                y(t_vis < -0.4 | t_vis > 0.4)=nan;
+                nsd=10;
+
+                if tt < 4 % no ms
+                    % remove ms window
+                    y(t_vis > 1) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t]; %#ok<*AGROW>
+                    end
+                elseif tt >= 4 && tt < 7 % ms @ -50
+                    % remove ms window
+                    y(t_vis > -0.07 & t_vis < -0.03) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t];
+                    end
+                elseif tt >= 7 && tt < 10 % ms @ +50
+                    % remove ms window
+                    y(t_vis > 0.04 & t_vis < 0.08) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t];
+                    end
+                elseif tt >= 10 % ms @ +150
+                    % remove ms window
+                    y(t_vis > 0.140 & t_vis < 0.180) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t];
+                    end
+                end
+            end
+
+            %================================================
+            % throw out fluctuating trials ------
+            st_all = sel_trials_clean>0;
+            if sel_files(1) == 0 % only a subset of trial with stable signal
+                st_1to16 = sel_trials_clean>=581 & sel_trials_clean<=1050;
+                st_17to32 = sel_trials_clean<=1050;
+            else
+                st_1to16 = st_all;
+                st_17to32 = st_all;
+            end
+            %================================================
+
+            TrialType{4,tt} = sel_trials_clean;
+            TrialType{5,tt} = [st_all;st_1to16;st_17to32];
+
+            if sC<17
+                sel_trials_clean = sel_trials_clean(st_1to16);
+            else
+                sel_trials_clean = sel_trials_clean(st_17to32);
+            end
+            TrialType{6,tt} = sel_trials_clean;
+
+            BL =  mean( D(CHi(1,sC)).Signal(:,CHi(2,sC),sel_trials_clean),3);
+        end
+
+        % threshold spikes ================================================
+        fprintf('Getting spikes\n');
+        TH = [V1FG.TH1(ff) V1FG.TH2(ff)];
+        if TH(1)<0
+            TH=[-TH 1];
+        else
+            TH=[TH -1];
+        end
+        PosNeg = TH(3);
+        for tt = [1:4,7,10:12]
+            spikes(tt).rast=[];
+            n=0;
+            for i=TrialType{6,tt} % 3 is all trials of the type, 4 is cleaned
+                n=n+1;
+                if MeanAlreadySubtracted
+                    y=D(CHi(1,sC)).Signal(:,CHi(2,sC),i);
+                else
+                    BL =  mean( D(CHi(1,sC)).Signal(:,CHi(2,sC),TrialType{6,tt}),3);
+                    y=D(CHi(1,sC)).Signal(:,CHi(2,sC),i)-BL;
+                end
+                [yp,xp] = findpeaks(double(PosNeg.*y),t_vis,...
+                    'MinPeakHeight',TH(1));
+                xp(yp>TH(2))=[];
+                yp(yp>TH(2))=[];
+
+                % REMOVE SPIKES THAT ARE WIWTHIN THE ARTEFACT WINDOW ======
+                if tt<4
+                    msi=0;
+                elseif tt<7
+                    msi=1;
+                elseif tt<10
+                    msi=2;
+                else
+                    msi=3;
+                end
+                if msi>0
+                    msw_5p = [ ...
+                        -0.058: 0.005:-0.0375 ;...
+                        0.050: 0.005: 0.0714 ;...
+                        0.150: 0.005: 0.1714 ];
+                    msw_w = 0.001;
+                    for ii=1:size(msw_5p,2)
+                        selspk = (xp >= msw_5p(msi,ii) & xp <= msw_5p(msi,ii)+msw_w);
+                        xp(selspk)=[];
+                        yp(selspk)=[];
+                    end
+                end
+                spikes(tt).rast=[spikes(tt).rast; xp' yp ones(size(yp))*n];
+            end
+
+            % new: sliding window
+            SlidWin.width = 0.010;
+            SlidWin.step = 0.001;
+            SlidWin.Min = -0.200;
+            SlidWin.Max = 0.350;
+
+            spikes(tt).bin=[];spikes(tt).n=[];
+            for t = (SlidWin.Min-(SlidWin.width/2)):SlidWin.step:(SlidWin.Max-(SlidWin.width/2))
+                y=sum(spikes(tt).rast(:,1) >= t & spikes(tt).rast(:,1) <= t+SlidWin.width)/...
+                    (SlidWin.width*max(spikes(tt).rast(:,3)));
+                spikes(tt).bin=[spikes(tt).bin t+(SlidWin.width/2)];
+                spikes(tt).n=[spikes(tt).n; y];
+            end
+            BinSpecs=[-200 10 400]./1000;
+
+        end
+        % collect
+        V1_FG(ff).info = V1FG(ff,:);
+        V1_FG(ff).spikes = spikes;
+        V1_FG(ff).TrialType = TrialType;
+        V1_FG(ff).SlidWin=SlidWin;
+        V1_FG(ff).BL = BL;
+        BL=[];
+        for tr = unique(V1_FG(ff).spikes(2).rast(:,3))'
+            [n,b] = ...
+                hist(V1_FG(ff).spikes(2).rast(V1_FG(ff).spikes(2).rast(:,3)==tr,1),...
+                BinSpecs(1):BinSpecs(2):BinSpecs(3));
+            BL=[BL nanmean(n(b>-0.1 & b<0))./BinSpecs(2)];
+        end
+        PK=max(V1_FG(ff).spikes(2).n(V1_FG(ff).spikes(2).bin>0 & V1_FG(ff).spikes(2).bin<0.06));
+        V1_FG(ff).SNR=(PK-mean(BL))/std(BL);
+    end
+    V1_FG_info = V1FG;
+    if MeanAlreadySubtracted
+        save(fullfile(fld.data,'V1FG_Selected2_5p'),...
+            'V1_FG','V1_FG_info','V1FG','-v7.3');
+    else
+        save(fullfile(fld.data,'V1FG_Selected_5p'),...
+            'V1_FG','V1_FG_info','V1FG','-v7.3');
+    end
+else
+    if MeanAlreadySubtracted
+        fprintf('Loading V1FG_Selected2_5p.mat\n');
+        load(fullfile(fld.data,'V1FG_Selected2_5p.mat'))
+    else
+        fprintf('Loading V1FG_Selected_5p.mat\n');
+        load(fullfile(fld.data,'V1FG_Selected_5p.mat'))
+    end
+end
+fprintf('DONE!\n');
+
+for entry = 1:size(V1_FG_info.notes,1)
+    if strcmp(V1_FG_info.notes{entry},'ReverseFG')
+        F0 = V1_FG(entry).TrialType(3:end,2);
+        G0 = V1_FG(entry).TrialType(3:end,3);
+        F1 = V1_FG(entry).TrialType(3:end,11);
+        G1 = V1_FG(entry).TrialType(3:end,12);
+        V1_FG(entry).TrialType(3:end,2)=G0;
+        V1_FG(entry).TrialType(3:end,3)=F0;
+        V1_FG(entry).TrialType(3:end,11)=G1;
+        V1_FG(entry).TrialType(3:end,12)=F1;
+
+        F0 = V1_FG(entry).spikes(2);
+        G0 = V1_FG(entry).spikes(3);
+        F1 = V1_FG(entry).spikes(11);
+        G1 = V1_FG(entry).spikes(12);
+        V1_FG(entry).spikes(2)=G0;
+        V1_FG(entry).spikes(3)=F0;
+        V1_FG(entry).spikes(11)=G1;
+        V1_FG(entry).spikes(12)=F1;
+    end
+end
+
+%% select a subset of combinations ======================================
+% opens a gui for data selection if not already donw
+if ~UseSelected
+    global select
+    select.monkey = 'Both'; select.vis = 'Yes';
+    select.fg = 'Yes'; select.ms = 'Any'; select.SNR = median([V1_FG.SNR]);
+    h = SelectFG;
+    smw=5;
+
+    % For SUP FIGURE 6 A-D: Both, VIS+, FG-BOTH, +|-, SNR>1
+    % For SUP FIGURE 6 F-I: Manny, VIS+, FG+, +|-, SNR>1
+end
+%% UpdateSelection ======================================================
+% updates variable after gui changes
+if ~UseSelected
+    for UpdateSelection=1
+        V1FG.visual(76)=0;
+        switch select.monkey
+            case 'Darwin'
+                monksel = strcmp(V1FG.Monkey,'Darwin');
+            case 'Manny'
+                monksel = strcmp(V1FG.Monkey,'Manny');
+            case 'Both'
+                monksel = ~strcmp(V1FG.Monkey,'NONSENSE');
+        end
+
+        switch select.vis
+            case 'Yes'
+                vissel = V1FG.visual==1;
+            case 'No'
+                vissel = V1FG.visual==0;
+            case 'Both'
+                vissel = V1FG.visual>=0;
+        end
+
+        switch select.fg
+            case 'Yes'
+                fgsel = V1FG.FG==1;
+            case 'No'
+                fgsel = V1FG.FG==0;
+            case 'Both'
+                fgsel = V1FG.FG>=0;
+        end
+
+        switch select.ms
+            case 'Any'
+                mssel = V1FG.HT_ms_exc>=0;
+            case 'Enhancement only'
+                mssel = V1FG.HT_ms_exc==1 & V1FG.HT_ms_inh==0;
+            case 'Supression only'
+                mssel = V1FG.HT_ms_exc==0 & V1FG.HT_ms_inh==1;
+            case 'Enhanced or Supressed'
+                mssel = V1FG.HT_ms_exc==1 | V1FG.HT_ms_inh==1;
+            case 'Enhanced & Supressed'
+                mssel = V1FG.HT_ms_exc==1 & V1FG.HT_ms_inh==1;
+            case 'None'
+                mssel = V1FG.HT_ms_exc==0 & V1FG.HT_ms_inh==0;
+        end
+
+        snrsel = [V1_FG.SNR]>=select.SNR;
+        snrsel = snrsel';
+
+        sel = mean([mssel fgsel vissel monksel snrsel],2)==1;
+        selstring = ['M: ' select.monkey ', Vis: ' select.vis ', FG: ' select.fg ', MS: ' select.ms];
+    end
+    %
+    N=sum(sel);
+    fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+
+    for tt=[1:4,7,10:12]
+        Avg(tt).y=[];
+        Avg(tt).yb=[];
+        Avg(tt).yn=[];
+        t = V1_FG(1).spikes(1).bin(2:end-1);
+
+        for s=find(sel>0)'
+            y=V1_FG(s).spikes(tt).n(2:end-1)';
+            %yh=V1_FG(s).spikes(1).n(2:end-1);
+            Avg(tt).y = [Avg(tt).y; y];
+            yb = mean(y(t>-0.150 & t<0));
+            %yhb = yh-mean(yh(t>-0.170 & t<-0.070));
+            Avg(tt).yb = [Avg(tt).yb; yb];
+            %yn = yb ./ max(yhb(t>0 & t<0.1));
+            %Avg(tt).yn = [Avg(tt).yn; yn];
+        end
+    end
+
+    bl=[];
+    for i=1:length(Avg)
+        bl=[bl Avg(i).yb];
+    end
+
+    pk=[];
+    for i=1:sum(sel)
+        sy=smooth(Avg(1).y(i,:),7);
+        pk=[pk; max(sy(t>0 & t<0.080))];
+    end
+
+    for tt=[1:4,7,10:12]
+        for s=1:sum(sel)
+            sbl = mean(bl(s,[1:3 5:8]),2);
+            spk = pk(s);
+            Avg(tt).yn(s,:) = (Avg(tt).y(s,:) - sbl)./(spk-sbl) ;
+        end
+    end
+
+    ms_win = [...
+        -0.064 -0.034   -0.024  0.126  ; ...
+        0.050  0.080    0.090  0.240  ; ...
+        0.150  0.180    0.190  0.340  ; ...
+        ];
+
+    sbin1a = find( (t>=ms_win(1,1) & t<ms_win(1,2))>0 );
+    sbin2a = find( (t>=ms_win(2,1) & t<ms_win(2,2))>0 );
+    sbin3a = find( (t>=ms_win(3,1) & t<ms_win(3,2))>0 );
+    sbin1b = find( (t>=ms_win(1,3) & t<ms_win(1,4))>0 );
+    sbin2b = find( (t>=ms_win(2,3) & t<ms_win(2,4))>0 );
+    sbin3b = find( (t>=ms_win(3,3) & t<ms_win(3,4))>0 );
+
+    for tt=[1:4,7,10:12]
+        Y{tt} = nanmean(Avg(tt).yn,1);
+        YS{tt} = smooth(Y{tt},smw);
+        Y2{tt} = YS{tt};
+        end
+end
+%% Figure/Ground plots ====================================================
+fprintf('FG-MS interaction plots, used in SUPP FIGURE 6F-I\n')
+
+if UseSelected
+    load(fullfile(fld.data,'Hardcoded_SOA_FG_sel.mat'));
+end
+
+t = V1_FG(1).spikes(1).bin(2:end-1);
+smoothing_window_ms = 10;
+smw = (smoothing_window_ms/1000)./mean(diff(t));
+
+figure('Position',[50 50 1800 1000]);
+subplot(2,6,1:2);hold on;
+plot(t,smooth(nanmean(Avg(2).yn,1),smw),'Color',[0 0.4 0],'LineWidth',2)
+plot(t,smooth(nanmean(Avg(3).yn,1),smw),'Color',[0.2 0 0.8],'LineWidth',2)
+legend({'Figure','Ground'},'Location','northwest');
+set(gca,'xlim',[-0.05 0.35],'ylim',[-.1 1]);
+title([selstring ': F&G responses'], 'interpreter', 'none');
+text(0.27,-0.02,['N = ' num2str(N)],'fontsize',12);
+
+subplot(2,6,7:8);hold on;
+area(t,smooth(nanmean(Avg(2).yn,1)-nanmean(Avg(3).yn,1),smw),...
+    'FaceColor',[0.8 0.8 0.8])
+legend({'Figure-Ground'},'Location','northwest');
+set(gca,'xlim',[-0.05 0.35],'ylim',[-.075 0.15]);
+title([selstring ': F-G'], 'interpreter', 'none');
+text(0.27,-0.05,['N = ' num2str(N)],'fontsize',12);
+
+% F/G interaction with MS 150 ms -----------------------------------------
+LC={[0 0.4 0],[0 0.8 0.2],[0 0 0.6],[0.2 0.8 0.8]};
+subplot(2,6,3:4); hold on;
+ci=0;
+for tt=[2,11,3,12]
+    ci=ci+1;
+    plot(t,smooth(Y2{tt},smw),'Color',LC{ci},'LineWidth',2)
+end
+legend({'FIG','FIG MS','GND','GND MS'},'Location','northeast');
+set(gca,'xlim',[-0.05 0.35],'ylim',[-.1 1]);
+title('F-G and MS@150ms', 'interpreter', 'none');
+
+for recompose_plots=1
+    y=nanmean(Avg(11).yn,1)-nanmean(Avg(2).yn,1);
+    ynan = y; ynan(sbin3a) = nan;
+    y2=smooth(ynan,smw);
+    y2(sbin3a)=y(sbin3a);
+    yy=nanmean(Avg(12).yn,1)-nanmean(Avg(3).yn,1);
+    yynan = yy; yynan(sbin3a) = nan;
+    yy2=smooth(yynan,smw);
+    yy2(sbin3a)=yy(sbin3a);
+end
+subplot(2,6,9:10);hold on;
+area(t,y2,'FaceColor',LC{1})
+legend({'FIG MS - NoMS'},'Location','southwest');
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[0.0 0.35],'ylim',[-0.2 0.25]);
+title('F-G and MS@150ms', 'interpreter', 'none');
+
+subplot(2,6,11:12);hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'GND MS - NoMS'},'Location','southwest');
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[0.0 0.35],'ylim',[-0.2 0.25]);
+title('F-G and MS@150ms', 'interpreter', 'none');
+
+% effect size
+FGMS = [ ...
+    sum(Avg(11).yn(:,sbin3a),2)./length(sbin3a) - ...
+    sum(Avg(2).yn(:,sbin3a),2)./length(sbin3a)...
+    sum(Avg(12).yn(:,sbin3a),2)./length(sbin3a) - ...
+    sum(Avg(3).yn(:,sbin3a),2)./length(sbin3a)...
+    sum(Avg(11).yn(:,sbin3b),2)./length(sbin3b) - ...
+    sum(Avg(2).yn(:,sbin3b),2)./length(sbin3b)...
+    sum(Avg(12).yn(:,sbin3b),2)./length(sbin3b) - ...
+    sum(Avg(3).yn(:,sbin3b),2)./length(sbin3b)];
+
+mFGMS = nanmean(FGMS,1);
+semFGMS = nanstd(FGMS)./sqrt(size(FGMS,1));
+subplot(2,6,5);hold on;
+bar(1,mFGMS(1), 'FaceColor',LC{1});
+bar(2,mFGMS(2), 'FaceColor',LC{3});
+errorbar(1:2,mFGMS(1:2),semFGMS(1:2),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 2.5],'xtick',[1,2],...
+    'xticklabel',{'Fig exc','Gnd exc'});
+title('MS effect @150ms', 'interpreter', 'none');
+
+subplot(2,6,6);hold on;
+bar(1,mFGMS(3), 'FaceColor',LC{1});
+bar(2,mFGMS(4), 'FaceColor',LC{3});
+errorbar(1:2,mFGMS(3:4),semFGMS(3:4),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 2.5],'xtick',[1,2],...
+    'xticklabel',{'Fig sup','Gnd sup'});
+title('MS effect @150ms', 'interpreter', 'none');
+
+%% MS timing plots ========================================================
+fprintf('FG-MS SOA plots\n')
+LC={[0 0 0],[0 0.4 0],[0.8 0 0],[0 0 0.6]};
+figure('Position',[50 50 1800 1000]);
+subplot(5,4,[1 5 9])
+hold on;
+ci=0;
+for tt=[1 4 7 10]
+    ci=ci+1;
+    plot(t,Y2{tt},'Color',LC{ci},'LineWidth',2)
+end
+legend({'no MS','-50ms','50ms','150ms'});
+set(gca,'xlim',[-0.1 0.35]);
+title([selstring ': MS-SOA effect'], 'interpreter', 'none');
+text(0.25,-0.4,['N = ' num2str(N)],'fontsize',12);
+
+subplot(5,4,[3 7 11])
+hold on;
+ci=0;
+for tt=[1 4 7 10]
+    ci=ci+1;
+    plot(t,Y2{tt},'Color',LC{ci},'LineWidth',2)
+end
+legend({'no MS','-50ms','50ms','150ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+yy=nanmean(Avg(4).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin1a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin1a)=yy(sbin1a);
+YY{1}=yy2;
+
+subplot(5,4,2)
+hold on;
+area(t,yy2,'FaceColor',LC{2})
+legend({'-50ms'});
+YLIM=get(gca,'ylim');
+plot([ms_win(1,1) ms_win(1,1)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(1,2) ms_win(1,2)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(1,3) ms_win(1,3)],[YLIM(1) YLIM(2)],'k--');
+plot([ms_win(1,4) ms_win(1,4)],[YLIM(1) YLIM(2)],'k--');
+set(gca,'xlim',[-0.1 0.35]);
+
+subplot(5,4,4)
+hold on;
+area(t,yy2,'FaceColor',LC{2})
+legend({'-50ms'});
+plot([ms_win(1,1) ms_win(1,1)],[-1 1],'k-');
+plot([ms_win(1,2) ms_win(1,2)],[-1 1],'k-');
+plot([ms_win(1,3) ms_win(1,3)],[-1 1],'k--');
+plot([ms_win(1,4) ms_win(1,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(7).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin2a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin2a)=yy(sbin2a);
+YY{2}=yy2;
+
+subplot(5,4,6)
+hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'50ms'});
+YLIM=get(gca,'ylim');
+plot([ms_win(2,1) ms_win(2,1)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(2,2) ms_win(2,2)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(2,3) ms_win(2,3)],[YLIM(1) YLIM(2)],'k--');
+plot([ms_win(2,4) ms_win(2,4)],[YLIM(1) YLIM(2)],'k--');
+set(gca,'xlim',[-0.1 0.35]);
+
+subplot(5,4,8)
+hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'50ms'});
+plot([ms_win(2,1) ms_win(2,1)],[-1 1],'k-');
+plot([ms_win(2,2) ms_win(2,2)],[-1 1],'k-');
+plot([ms_win(2,3) ms_win(2,3)],[-1 1],'k--');
+plot([ms_win(2,4) ms_win(2,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(10).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin3a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin3a)=yy(sbin3a);
+YY{3}=yy2;
+
+subplot(5,4,10)
+hold on;
+area(t,yy2,'FaceColor',LC{4})
+legend({'150ms'});
+YLIM=get(gca,'ylim');
+plot([ms_win(3,1) ms_win(3,1)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[YLIM(1) YLIM(2)],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[YLIM(1) YLIM(2)],'k--');
+set(gca,'xlim',[-0.1 0.35]);
+
+subplot(5,4,12)
+hold on;
+area(t,yy2,'FaceColor',LC{4})
+legend({'150ms'});
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+% ------------------------------------------------------------------
+subplot(5,4,[13,14,17,18]);
+hold on;
+plot(t+0.060,YY{1},'Color',LC{2},'LineWidth',2)
+plot(t-0.050,YY{2},'Color',LC{3},'LineWidth',2)
+plot(t-0.150,YY{3},'Color',LC{4},'LineWidth',2)
+set(gca,'xlim',[-0.1 0.2],'ylim',[-0.3 5]);
+title([selstring ': MS-SOA ALIGNED to MS'], 'interpreter', 'none');
+text(-0.075,1,['N = ' num2str(N)],'fontsize',12);
+
+MS_SOA = [sum(Avg(4).yn(:,sbin1a),2)./length(sbin1a) - sum(Avg(1).yn(:,sbin1a),2)./length(sbin1a) ...
+    sum(Avg(7).yn(:,sbin2a),2)./length(sbin2a) - sum(Avg(1).yn(:,sbin2a),2)./length(sbin2a) ...
+    sum(Avg(10).yn(:,sbin3a),2)./length(sbin3a) - sum(Avg(1).yn(:,sbin3a),2)./length(sbin3a) ...
+    sum(Avg(4).yn(:,sbin1b),2)./length(sbin1b) - sum(Avg(1).yn(:,sbin1b),2)./length(sbin1b) ...
+    sum(Avg(7).yn(:,sbin2b),2)./length(sbin2b) - sum(Avg(1).yn(:,sbin2b),2)./length(sbin2b) ...
+    sum(Avg(10).yn(:,sbin3b),2)./length(sbin3b) - sum(Avg(1).yn(:,sbin3b),2)./length(sbin3b)];
+
+mMS_SOA = nanmean(MS_SOA);
+semFGMS = nanstd(MS_SOA)./sqrt(size(MS_SOA,1));
+
+subplot(5,4,[15,19]);
+hold on
+bar(1,mMS_SOA(1), 'FaceColor',LC{2});
+bar(2,mMS_SOA(2), 'FaceColor',LC{3});
+bar(3,mMS_SOA(3), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(1:3),semFGMS(1:3),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Exc. effect', 'interpreter', 'none');
+
+subplot(5,4,[16,20]);
+hold on
+bar(1,mMS_SOA(4), 'FaceColor',LC{2});
+bar(2,mMS_SOA(5), 'FaceColor',LC{3});
+bar(3,mMS_SOA(6), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(4:6),semFGMS(4:6),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Supp. effect', 'interpreter', 'none')
+
+%% MS timing second plot ==================================================
+fprintf('These plots are used for SUPP FIGURE 6A-D\n')
+
+LC={[0 0 0],[0 0.4 0],[0.8 0 0],[0 0 0.6]};
+figure('Position',[50 50 1800 1000]);
+
+subplot(3,3,1); hold on;
+plot(t,Y2{1},'Color',LC{1},'LineWidth',2)
+plot(t,Y2{4},'Color',LC{2},'LineWidth',2)
+legend({'no MS','-50ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+subplot(3,3,2); hold on;
+plot(t,Y2{1},'Color',LC{1},'LineWidth',2)
+plot(t,Y2{7},'Color',LC{3},'LineWidth',2)
+legend({'no MS','50ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+subplot(3,3,3); hold on;
+plot(t,Y2{1},'Color',LC{1},'LineWidth',2)
+plot(t,Y2{10},'Color',LC{4},'LineWidth',2)
+legend({'no MS','150ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+yy=nanmean(Avg(4).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin1a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin1a)=yy(sbin1a);
+YY{1}=yy2;
+
+subplot(3,3,4); hold on;
+area(t,yy2,'FaceColor',LC{2})
+legend({'-50ms'});
+plot([ms_win(1,1) ms_win(1,1)],[-1 1],'k-');
+plot([ms_win(1,2) ms_win(1,2)],[-1 1],'k-');
+plot([ms_win(1,3) ms_win(1,3)],[-1 1],'k--');
+plot([ms_win(1,4) ms_win(1,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(7).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin2a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin2a)=yy(sbin2a);
+YY{2}=yy2;
+
+subplot(3,3,5); hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'50ms'});
+plot([ms_win(2,1) ms_win(2,1)],[-1 1],'k-');
+plot([ms_win(2,2) ms_win(2,2)],[-1 1],'k-');
+plot([ms_win(2,3) ms_win(2,3)],[-1 1],'k--');
+plot([ms_win(2,4) ms_win(2,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(10).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin3a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin3a)=yy(sbin3a);
+YY{3}=yy2;
+
+subplot(3,3,6); hold on;
+area(t,yy2,'FaceColor',LC{4})
+legend({'150ms'});
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+subplot(3,3,7); hold on;
+plot([-1 1],[0,0],'k');
+plot(t+0.060,YY{1},'Color',LC{2},'LineWidth',2)
+plot(t-0.050,YY{2},'Color',LC{3},'LineWidth',2)
+plot(t-0.150,YY{3},'Color',LC{4},'LineWidth',2)
+set(gca,'xlim',[-0.1 0.2],'ylim',[-0.3 1]);
+title([selstring ': MS-SOA ALIGNED to MS'], 'interpreter', 'none');
+
+MS_SOA = [sum(Avg(4).yn(:,sbin1a),2)./length(sbin1a) - ...
+    sum(Avg(1).yn(:,sbin1a),2)./length(sbin1a) ...
+    sum(Avg(7).yn(:,sbin2a),2)./length(sbin2a) - ...
+    sum(Avg(1).yn(:,sbin2a),2)./length(sbin2a) ...
+    sum(Avg(10).yn(:,sbin3a),2)./length(sbin3a) - ...
+    sum(Avg(1).yn(:,sbin3a),2)./length(sbin3a) ...
+    sum(Avg(4).yn(:,sbin1b),2)./length(sbin1b) - ...
+    sum(Avg(1).yn(:,sbin1b),2)./length(sbin1b) ...
+    sum(Avg(7).yn(:,sbin2b),2)./length(sbin2b) - ...
+    sum(Avg(1).yn(:,sbin2b),2)./length(sbin2b) ...
+    sum(Avg(10).yn(:,sbin3b),2)./length(sbin3b) - ...
+    sum(Avg(1).yn(:,sbin3b),2)./length(sbin3b)];
+
+mMS_SOA = nanmean(MS_SOA);
+semFGMS = nanstd(MS_SOA)./sqrt(size(MS_SOA,1));
+
+subplot(3,3,8); hold on;
+bar(1,mMS_SOA(1), 'FaceColor',LC{2});
+bar(2,mMS_SOA(2), 'FaceColor',LC{3});
+bar(3,mMS_SOA(3), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(1:3),semFGMS(1:3),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Exc. effect', 'interpreter', 'none');
+
+subplot(3,3,9); hold on;
+bar(1,mMS_SOA(4), 'FaceColor',LC{2});
+bar(2,mMS_SOA(5), 'FaceColor',LC{3});
+bar(3,mMS_SOA(6), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(4:6),semFGMS(4:6),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Supp. effect', 'interpreter', 'none')
+
+%% Statistics SOA =========================================================
+fprintf('...and the corresponding statistics\n')
+
+% Hardcoded selections
+load(fullfile(fld.data,'Hardcoded_SOA_FG_sel.mat'));
+sel=SOA_sel; N=sum(sel);
+clear sbin
+fprintf('\n\n==== SOA STATISTICS ====\n');
+fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+ttail_exc='both'; % right
+ttail_sup='both'; % left
+
+for Collect=1
+    for tt=[1:4,7,10:12]
+        Avg(tt).y=[];
+        Avg(tt).yb=[];
+        Avg(tt).yn=[];
+        t = V1_FG(1).spikes(1).bin(2:end-1);
+        for s=find(sel>0)'
+            y=V1_FG(s).spikes(tt).n(2:end-1)';
+            Avg(tt).y = [Avg(tt).y; y];
+            yb = mean(y(t>-0.150 & t<0));
+            Avg(tt).yb = [Avg(tt).yb; yb];
+        end
+    end
+    bl=[]; for i=1:length(Avg); bl=[bl Avg(i).yb]; end
+    pk=[];
+    for i=1:sum(sel)
+        sy=smooth(Avg(1).y(i,:),7);
+        pk=[pk; max(sy(t>0 & t<0.080))];
+    end
+    for tt=[1:4,7,10:12]
+        for s=1:sum(sel)
+            sbl = mean(bl(s,[1:3 5:8]),2);
+            spk = pk(s);
+            Avg(tt).yn(s,:) = (Avg(tt).y(s,:) - sbl)./(spk-sbl) ;
+        end
+    end
+    ms_win = [...
+        -0.064 -0.034   -0.024  0.136  ; ...
+        0.050  0.080    0.090  0.250  ; ...
+        0.150  0.180    0.190  0.350  ; ...
+        ];
+    for mt=1:3
+        for w=1:2
+            sbin{mt,w} = find( (t>=ms_win(mt,2*(w-1)+1) & ...
+                t<ms_win(mt,2*(w-1)+2)>0) );
+        end
+    end
+end
+
+MS_SOA = [...
+    sum(Avg(4).yn(:,sbin{1,1}),2)./length(sbin{1,1}) - ...
+    sum(Avg(1).yn(:,sbin{1,1}),2)./length(sbin{1,1}) ...
+    sum(Avg(7).yn(:,sbin{2,1}),2)./length(sbin{2,1}) - ...
+    sum(Avg(1).yn(:,sbin{2,1}),2)./length(sbin{2,1}) ...
+    sum(Avg(10).yn(:,sbin{3,1}),2)./length(sbin{3,1}) - ...
+    sum(Avg(1).yn(:,sbin{3,1}),2)./length(sbin{3,1}) ...
+    sum(Avg(4).yn(:,sbin{1,2}),2)./length(sbin{1,2}) - ...
+    sum(Avg(1).yn(:,sbin{1,2}),2)./length(sbin{1,2}) ...
+    sum(Avg(7).yn(:,sbin{2,2}),2)./length(sbin{2,2}) - ...
+    sum(Avg(1).yn(:,sbin{2,2}),2)./length(sbin{2,2}) ...
+    sum(Avg(10).yn(:,sbin{3,2}),2)./length(sbin{3,2}) - ...
+    sum(Avg(1).yn(:,sbin{3,2}),2)./length(sbin{3,2})  ];
+
+for mt = 1:3
+    SOA(mt).Exc.val = MS_SOA(:,mt);
+    [SOA(mt).Exc.H,SOA(mt).Exc.p, SOA(mt).Exc.ci, SOA(mt).Exc.stats] = ...
+        ttest(SOA(mt).Exc.val,0,'tail',ttail_exc);
+    fprintf(['\nMicrostim induced excitation @time ' num2str(mt) ':\n' ...
+        't(' num2str(SOA(mt).Exc.stats.df) ') = ' num2str(SOA(mt).Exc.stats.tstat) ...
+        ', p = ' num2str(SOA(mt).Exc.p) '\n']);
+
+    SOA(mt).Sup.val = MS_SOA(:,3+mt);
+    [SOA(mt).Sup.H,SOA(mt).Sup.p, SOA(mt).Sup.ci, SOA(mt).Sup.stats] = ...
+        ttest(SOA(mt).Sup.val,0,'tail',ttail_sup);
+    fprintf(['\nMicrostim induced suppression @time ' num2str(mt) ':\n' ...
+        't(' num2str(SOA(mt).Sup.stats.df) ') = ' num2str(SOA(mt).Sup.stats.tstat) ...
+        ', p = ' num2str(SOA(mt).Sup.p) '\n']);
+end
+
+[SOA(4).Exc.p,SOA(4).Exc.ANOVA,SOA(4).Exc.stats] = ...
+    anova1(MS_SOA(:,1:3),{'-58','+50','+150'});
+[SOA(4).Exc.MultComp.c,SOA(4).Exc.MultComp.m,SOA(4).Exc.MultComp.h] = ...
+    multcompare(SOA(4).Exc.stats);
+SOA(4).Exc.MultComp.p = SOA(4).Exc.MultComp.c(:,6)';
+
+[SOA(4).Sup.p,SOA(4).Sup.ANOVA,SOA(4).Sup.stats] = ...
+    anova1(MS_SOA(:,4:6),{'-58','+50','+150'});
+[SOA(4).Sup.MultComp.c,SOA(4).Sup.MultComp.m,SOA(4).Sup.MultComp.h] = ...
+    multcompare(SOA(4).Sup.stats);
+SOA(4).Sup.MultComp.p = SOA(4).Sup.MultComp.c(:,6)';
+
+fprintf(['\nTiming dependence of excitation effect:\n' ...
+    'ANOVA: F(' num2str(SOA(4).Exc.ANOVA{2,3}) ',' ...
+    num2str(SOA(4).Exc.ANOVA{3,3}) ') = ' ...
+    num2str(SOA(4).Exc.ANOVA{2,5}) ', p = ' num2str(SOA(4).Exc.p) '\n']);
+fprintf(['Multiple comparisons, p-values ['...
+    num2str(SOA(4).Exc.MultComp.p(1)) ' ' ...
+    num2str(SOA(4).Exc.MultComp.p(2)) ' ' ...
+    num2str(SOA(4).Exc.MultComp.p(3)) ']\n']);
+fprintf(['\nTiming dependence of suppression effect:\n' ...
+    'ANOVA: F(' num2str(SOA(4).Sup.ANOVA{2,3}) ',' ...
+    num2str(SOA(4).Sup.ANOVA{3,3}) ') = ' ...
+    num2str(SOA(4).Sup.ANOVA{2,5}) ', p = ' num2str(SOA(4).Sup.p) '\n']);
+fprintf(['Multiple comparisons, p-values ['...
+    num2str(SOA(4).Sup.MultComp.p(1)) ' ' ...
+    num2str(SOA(4).Sup.MultComp.p(2)) ' ' ...
+    num2str(SOA(4).Sup.MultComp.p(3)) ']\n']);
+
+%% Statistics FG-GND ======================================================
+% Hardcoded selections
+load(fullfile(fld.data,'Hardcoded_SOA_FG_sel.mat'));
+sel=FG_sel; N=sum(sel);
+clear sbin
+fprintf('\n\n==== FIGURE-GROUND STATISTICS ====\n');
+fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+ttail_fg='right'; % right
+ttail_exc='right'; % right
+ttail_sup='left'; % left
+
+for Collect=1
+    for tt=[1:4,7,10:12]
+        Avg(tt).y=[];
+        Avg(tt).yb=[];
+        Avg(tt).yn=[];
+        t = V1_FG(1).spikes(1).bin(2:end-1);
+        for s=find(sel>0)'
+            y=V1_FG(s).spikes(tt).n(2:end-1)';
+            Avg(tt).y = [Avg(tt).y; y];
+            yb = mean(y(t>-0.150 & t<0));
+            Avg(tt).yb = [Avg(tt).yb; yb];
+        end
+    end
+    bl=[]; for i=1:length(Avg); bl=[bl Avg(i).yb]; end
+    pk=[];
+    for i=1:sum(sel)
+        sy=smooth(Avg(1).y(i,:),7);
+        pk=[pk; max(sy(t>0 & t<0.080))];
+    end
+    for tt=[1:4,7,10:12]
+        for s=1:sum(sel)
+            sbl = mean(bl(s,[1:3 5:8]),2);
+            spk = pk(s);
+            Avg(tt).yn(s,:) = (Avg(tt).y(s,:) - sbl)./(spk-sbl) ;
+        end
+    end
+    ms_win = [...
+        -0.064 -0.034   -0.024  0.136  ; ...
+        0.050  0.080    0.090  0.250  ; ...
+        0.150  0.180    0.190  0.350  ; ...
+        ];
+    fg_win = [0.150 0.350];
+    for mt=1:3
+        for w=1:2
+            sbin{mt,w} = find( (t>=ms_win(mt,2*(w-1)+1) & ...
+                t<ms_win(mt,2*(w-1)+2)>0) );
+        end
+    end
+    fgbin = find( (t>=fg_win(1) & t<fg_win(2)>0) );
+end
+
+
+FG_mod = sum( Avg(2).yn(:,fgbin)-Avg(3).yn(:,fgbin) ,2)./length(fgbin);
+[FG.Mod.H,FG.Mod.p,FG.Mod.ci,FG.Mod.stats] = ...
+    ttest(FG_mod,0,'tail',ttail_fg);
+fprintf(['\nFigure-Ground modulation:\n' ...
+    't(' num2str(FG.Mod.stats.df) ') = ' num2str(FG.Mod.stats.tstat) ...
+    ', p = ' num2str(FG.Mod.p) '\n']);
+fprintf('---------\n');
+
+MS_FG = [...
+    sum(Avg(11).yn(:,sbin{3,1}),2)./length(sbin{3,1}) - ...
+    sum(Avg(2).yn(:,sbin{3,1}),2)./length(sbin{3,1}) ...
+    sum(Avg(12).yn(:,sbin{3,1}),2)./length(sbin{3,1}) - ...
+    sum(Avg(3).yn(:,sbin{3,1}),2)./length(sbin{3,1}) ...
+    sum(Avg(11).yn(:,sbin{3,2}),2)./length(sbin{3,2}) - ...
+    sum(Avg(2).yn(:,sbin{3,2}),2)./length(sbin{3,2}) ...
+    sum(Avg(12).yn(:,sbin{3,2}),2)./length(sbin{3,2}) - ...
+    sum(Avg(3).yn(:,sbin{3,2}),2)./length(sbin{3,2}) ];
+
+FG.Exc.val = MS_FG(:,1);
+[FG.Exc.H,FG.Exc.p,FG.Exc.ci,FG.Exc.stats] = ...
+    ttest(FG.Exc.val,0,'tail',ttail_exc);
+fprintf(['\nMicrostim induced excitation FIG:\n' ...
+    't(' num2str(FG.Exc.stats.df) ') = ' num2str(FG.Exc.stats.tstat) ...
+    ', p = ' num2str(FG.Exc.p) '\n']);
+
+GND.Exc.val = MS_FG(:,2);
+[GND.Exc.H,GND.Exc.p,GND.Exc.ci,GND.Exc.stats] = ...
+    ttest(GND.Exc.val,0,'tail',ttail_exc);
+fprintf(['\nMicrostim induced excitation GND:\n' ...
+    't(' num2str(GND.Exc.stats.df) ') = ' num2str(GND.Exc.stats.tstat) ...
+    ', p = ' num2str(GND.Exc.p) '\n']);
+
+FG.Sup.val = MS_FG(:,3);
+[FG.Sup.H,FG.Sup.p,FG.Sup.ci,FG.Sup.stats] = ...
+    ttest(FG.Sup.val,0,'tail',ttail_sup);
+fprintf(['\nMicrostim induced suppression FIG:\n' ...
+    't(' num2str(FG.Sup.stats.df) ') = ' num2str(FG.Sup.stats.tstat) ...
+    ', p = ' num2str(FG.Sup.p) '\n']);
+
+GND.Sup.val = MS_FG(:,4);
+[GND.Sup.H,GND.Sup.p,GND.Sup.ci,GND.Sup.stats] = ...
+    ttest(GND.Sup.val,0,'tail',ttail_sup);
+fprintf(['\nMicrostim induced suppression GND:\n' ...
+    't(' num2str(GND.Sup.stats.df) ') = ' num2str(GND.Sup.stats.tstat) ...
+    ', p = ' num2str(GND.Sup.p) '\n']);
+
+[FgGnd.Exc.p,FgGnd.Exc.ANOVA,FgGnd.Exc.stats] = ...
+    anova1([FG.Exc.val GND.Exc.val],{'FIG','GND'});
+[FgGnd.Sup.p,FgGnd.Sup.ANOVA,FgGnd.Sup.stats] = ...
+    anova1([FG.Sup.val GND.Sup.val],{'FIG','GND'});
+
+fprintf(['\nFig-Gnd dependence of excitation effect:\n' ...
+    'ANOVA: F(' num2str(FgGnd.Exc.ANOVA{2,3}) ',' ...
+    num2str(FgGnd.Exc.ANOVA{2,3}) ') = ' ...
+    num2str(FgGnd.Exc.ANOVA{3,5}) ', p = ' num2str(FgGnd.Exc.p) '\n']);
+fprintf(['\nFig-Gnd dependence of suppression effect:\n' ...
+    'ANOVA: F(' num2str(FgGnd.Sup.ANOVA{2,3}) ',' ...
+    num2str(FgGnd.Sup.ANOVA{2,3}) ') = ' ...
+    num2str(FgGnd.Sup.ANOVA{3,5}) ', p = ' num2str(FgGnd.Sup.p) '\n']);

+ 976 - 0
SCRIPTS/FUNCTIONS/FG_spikes_ms5p.m

@@ -0,0 +1,976 @@
+%% Population analysis of the SOA and Figure-Ground data SPIKES =========
+% ------------------------------------------------------------
+% Loads an overview table of data to potentially include, imports the
+% bandpass filtered data and saves it together in a population data file.
+% Once this has been done, it can also directly load this file and work
+% with that.
+
+% 5 pulse version !!
+
+% after collecting data, we can simply load the presaved population file
+presaved = true;
+MeanAlreadySubtracted = true;
+
+%% load info ============================================================
+% this file contains the info about individual files
+load(fullfile(fld.data,'V1V1_FG_5p.mat'));
+
+%% load data & get spikes ===============================================
+if ~presaved
+    curr_sel = 0;
+    for ff=1:length(V1FG.Day)
+        indstr = V1FG.indeces(ff);
+        sep = find(indstr{1}=='_'==1);
+        sel_files = ...
+            [str2double(indstr{1}(1:sep-1)) str2double(indstr{1}(sep+1:end))];
+        if curr_sel ~= sel_files(1) % only load files once
+            curr_sel=sel_files(1);
+
+            if MeanAlreadySubtracted
+                % << artefact removal in raw
+                cd(fullfile(fld.data,'BANDPASS','BP2','500to5000'));
+            else
+                % << first BP version (no artefact removal in raw)
+                cd(fullfile(fld.data,'BANDPASS','BP','500to5000'));
+            end
+
+            CHMap = [1:16;17:32];
+            CHi = [ones(1,16) ones(1,16).*2 ; 1:16 1:16];
+
+            for df=1:2
+                fprintf(['Loading ' filenames{sel_files(df)} '\n']);
+                load(filenames{sel_files(df)},'Data')
+                D(df)=Data; clear Data; %#ok<*SAGROW>
+                t_vis = D(df).Time;
+            end
+            cd(fld.scripts)
+
+            MStime={'none',-50,50 150};
+            StimType={'Homogenous','Figure','Ground'};
+            typenum=0;
+
+            % categorize trials
+            for m=1:length(MStime)
+                for s=1:length(StimType)
+                    typenum=typenum+1;
+                    Trial(s,m).num = typenum;
+                    Trial(s,m).stim=StimType{s};
+                    Trial(s,m).ms = MStime{m};
+                    Trial(s,m).sel_trials = ...
+                        ~isnan(D(CHi(1,1)).Trials(:,3)) & ...
+                        D(CHi(1,1)).Trials(:,end)==typenum;
+                    Trial(s,m).i =(find(Trial(s,m).sel_trials==1))';
+                    TrialType{1,typenum} = StimType{s};
+                    TrialType{2,typenum} = MStime{m};
+                    TrialType{3,typenum} = Trial(s,m).i;
+                end
+            end
+        end
+        sC = V1FG.rec_channel(ff);
+        MUA = cell(12,2);
+        for tt =  1:size(TrialType,2)
+            sel_trials = TrialType{3,tt};
+            sel_trials_clean = [];
+
+            % check for artefacts
+            for t = sel_trials
+                sd = std(D(CHi(1,sC)).Signal(:,CHi(2,sC),t));
+                y = D(CHi(1,sC)).Signal(:,CHi(2,sC),t);
+                y(t_vis < -0.4 | t_vis > 0.4)=nan;
+                nsd=10;
+
+                if tt < 4 % no ms
+                    % remove ms window
+                    y(t_vis > 1) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t]; %#ok<*AGROW>
+                    end
+                elseif tt >= 4 && tt < 7 % ms @ -50
+                    % remove ms window
+                    y(t_vis > -0.07 & t_vis < -0.03) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t];
+                    end
+                elseif tt >= 7 && tt < 10 % ms @ +50
+                    % remove ms window
+                    y(t_vis > 0.04 & t_vis < 0.08) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t];
+                    end
+                elseif tt >= 10 % ms @ +150
+                    % remove ms window
+                    y(t_vis > 0.140 & t_vis < 0.180) = nan; % never true, because no MS
+                    % find exces values
+                    if sum(abs(y)>(nsd*sd)) > 0 % excessive values detected
+                    else
+                        sel_trials_clean=[sel_trials_clean t];
+                    end
+                end
+            end
+
+            %================================================
+            % throw out fluctuating trials ------
+            st_all = sel_trials_clean>0;
+            if sel_files(1) == 0 % only a subset of trial with stable signal
+                st_1to16 = sel_trials_clean>=581 & sel_trials_clean<=1050;
+                st_17to32 = sel_trials_clean<=1050;
+            else
+                st_1to16 = st_all;
+                st_17to32 = st_all;
+            end
+            %================================================
+
+            TrialType{4,tt} = sel_trials_clean;
+            TrialType{5,tt} = [st_all;st_1to16;st_17to32];
+
+            if sC<17
+                sel_trials_clean = sel_trials_clean(st_1to16);
+            else
+                sel_trials_clean = sel_trials_clean(st_17to32);
+            end
+            TrialType{6,tt} = sel_trials_clean;
+
+            BL =  mean( D(CHi(1,sC)).Signal(:,CHi(2,sC),sel_trials_clean),3);
+        end
+
+        % threshold spikes ================================================
+        fprintf('Getting spikes\n');
+        TH = [V1FG.TH1(ff) V1FG.TH2(ff)];
+        if TH(1)<0
+            TH=[-TH 1];
+        else
+            TH=[TH -1];
+        end
+        PosNeg = TH(3);
+        for tt = [1:4,7,10:12]
+            spikes(tt).rast=[];
+            n=0;
+            for i=TrialType{6,tt} % 3 is all trials of the type, 4 is cleaned
+                n=n+1;
+                if MeanAlreadySubtracted
+                    y=D(CHi(1,sC)).Signal(:,CHi(2,sC),i);
+                else
+                    BL =  mean( D(CHi(1,sC)).Signal(:,CHi(2,sC),TrialType{6,tt}),3);
+                    y=D(CHi(1,sC)).Signal(:,CHi(2,sC),i)-BL;
+                end
+                [yp,xp] = findpeaks(double(PosNeg.*y),t_vis,...
+                    'MinPeakHeight',TH(1));
+                xp(yp>TH(2))=[];
+                yp(yp>TH(2))=[];
+
+                % REMOVE SPIKES THAT ARE WIWTHIN THE ARTEFACT WINDOW ======
+                if tt<4
+                    msi=0;
+                elseif tt<7
+                    msi=1;
+                elseif tt<10
+                    msi=2;
+                else
+                    msi=3;
+                end
+                if msi>0
+                    msw_5p = [ ...
+                        -0.058: 0.005:-0.0375 ;...
+                        0.050: 0.005: 0.0714 ;...
+                        0.150: 0.005: 0.1714 ];
+                    msw_w = 0.001;
+                    for ii=1:size(msw_5p,2)
+                        selspk = (xp >= msw_5p(msi,ii) & xp <= msw_5p(msi,ii)+msw_w);
+                        xp(selspk)=[];
+                        yp(selspk)=[];
+                    end
+                end
+                spikes(tt).rast=[spikes(tt).rast; xp' yp ones(size(yp))*n];
+            end
+
+            % new: sliding window
+            SlidWin.width = 0.010;
+            SlidWin.step = 0.001;
+            SlidWin.Min = -0.200;
+            SlidWin.Max = 0.350;
+
+            spikes(tt).bin=[];spikes(tt).n=[];
+            for t = (SlidWin.Min-(SlidWin.width/2)):SlidWin.step:(SlidWin.Max-(SlidWin.width/2))
+                y=sum(spikes(tt).rast(:,1) >= t & spikes(tt).rast(:,1) <= t+SlidWin.width)/...
+                    (SlidWin.width*max(spikes(tt).rast(:,3)));
+                spikes(tt).bin=[spikes(tt).bin t+(SlidWin.width/2)];
+                spikes(tt).n=[spikes(tt).n; y];
+            end
+            BinSpecs=[-200 10 400]./1000;
+
+        end
+        % collect
+        V1_FG(ff).info = V1FG(ff,:);
+        V1_FG(ff).spikes = spikes;
+        V1_FG(ff).TrialType = TrialType;
+        V1_FG(ff).SlidWin=SlidWin;
+        V1_FG(ff).BL = BL;
+        BL=[];
+        for tr = unique(V1_FG(ff).spikes(2).rast(:,3))'
+            [n,b] = ...
+                hist(V1_FG(ff).spikes(2).rast(V1_FG(ff).spikes(2).rast(:,3)==tr,1),...
+                BinSpecs(1):BinSpecs(2):BinSpecs(3));
+            BL=[BL nanmean(n(b>-0.1 & b<0))./BinSpecs(2)];
+        end
+        PK=max(V1_FG(ff).spikes(2).n(V1_FG(ff).spikes(2).bin>0 & V1_FG(ff).spikes(2).bin<0.06));
+        V1_FG(ff).SNR=(PK-mean(BL))/std(BL);
+    end
+    V1_FG_info = V1FG;
+    if MeanAlreadySubtracted
+        save(fullfile(fld.data,'V1FG_Selected2_5p'),...
+            'V1_FG','V1_FG_info','V1FG','-v7.3');
+    else
+        save(fullfile(fld.data,'V1FG_Selected_5p'),...
+            'V1_FG','V1_FG_info','V1FG','-v7.3');
+    end
+else
+    if MeanAlreadySubtracted
+        fprintf('Loading V1FG_Selected2_5p.mat\n');
+        load(fullfile(fld.data,'V1FG_Selected2_5p.mat'))
+    else
+        fprintf('Loading V1FG_Selected_5p.mat\n');
+        load(fullfile(fld.data,'V1FG_Selected_5p.mat'))
+    end
+end
+fprintf('DONE!\n');
+
+for entry = 1:size(V1_FG_info.notes,1)
+    if strcmp(V1_FG_info.notes{entry},'ReverseFG')
+        F0 = V1_FG(entry).TrialType(3:end,2);
+        G0 = V1_FG(entry).TrialType(3:end,3);
+        F1 = V1_FG(entry).TrialType(3:end,11);
+        G1 = V1_FG(entry).TrialType(3:end,12);
+        V1_FG(entry).TrialType(3:end,2)=G0;
+        V1_FG(entry).TrialType(3:end,3)=F0;
+        V1_FG(entry).TrialType(3:end,11)=G1;
+        V1_FG(entry).TrialType(3:end,12)=F1;
+
+        F0 = V1_FG(entry).spikes(2);
+        G0 = V1_FG(entry).spikes(3);
+        F1 = V1_FG(entry).spikes(11);
+        G1 = V1_FG(entry).spikes(12);
+        V1_FG(entry).spikes(2)=G0;
+        V1_FG(entry).spikes(3)=F0;
+        V1_FG(entry).spikes(11)=G1;
+        V1_FG(entry).spikes(12)=F1;
+    end
+end
+
+%% select a subset of combinations ======================================
+% opens a gui for data selection
+global select
+select.monkey = 'Both';
+select.vis = 'Yes';
+select.fg = 'Yes';
+select.ms = 'Any';
+select.SNR = 1;
+h = SelectFG;
+smw=5;
+
+% For SUP FIGURE 6 A-D: Both, VIS+, FG-BOTH, +|-, SNR>1
+% For SUP FIGURE 6 F-I: Manny, VIS+, FG+, +|-, SNR>1
+
+% wait while gui is open, continue when closed
+if isvalid(h)
+    waitfor(h);
+end
+
+%% UpdateSelection ======================================================
+% updates variable after gui changes
+V1FG.visual(76)=0;
+switch select.monkey
+    case 'Darwin'
+        monksel = strcmp(V1FG.Monkey,'Darwin');
+    case 'Manny'
+        monksel = strcmp(V1FG.Monkey,'Manny');
+    case 'Both'
+        monksel = ~strcmp(V1FG.Monkey,'NONSENSE');
+end
+
+switch select.vis
+    case 'Yes'
+        vissel = V1FG.visual==1;
+    case 'No'
+        vissel = V1FG.visual==0;
+    case 'Both'
+        vissel = V1FG.visual>=0;
+end
+
+switch select.fg
+    case 'Yes'
+        fgsel = V1FG.FG==1;
+    case 'No'
+        fgsel = V1FG.FG==0;
+    case 'Both'
+        fgsel = V1FG.FG>=0;
+end
+
+switch select.ms
+    case 'Any'
+        mssel = V1FG.HT_ms_exc>=0;
+    case 'Enhancement only'
+        mssel = V1FG.HT_ms_exc==1 & V1FG.HT_ms_inh==0;
+    case 'Supression only'
+        mssel = V1FG.HT_ms_exc==0 & V1FG.HT_ms_inh==1;
+    case 'Enhanced or Supressed'
+        mssel = V1FG.HT_ms_exc==1 | V1FG.HT_ms_inh==1;
+    case 'Enhanced & Supressed'
+        mssel = V1FG.HT_ms_exc==1 & V1FG.HT_ms_inh==1;
+    case 'None'
+        mssel = V1FG.HT_ms_exc==0 & V1FG.HT_ms_inh==0;
+end
+
+snrsel = [V1_FG.SNR]>=select.SNR;
+snrsel = snrsel';
+
+sel = mean([mssel fgsel vissel monksel snrsel],2)==1;
+selstring = ['M: ' select.monkey ', Vis: ' select.vis ...
+    ', FG: ' select.fg ', MS: ' select.ms];
+%
+N=sum(sel);
+fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+
+
+for tt=[1:4,7,10:12]
+    Avg(tt).y=[];
+    Avg(tt).yb=[];
+    Avg(tt).yn=[];
+    t = V1_FG(1).spikes(1).bin(2:end-1);
+
+    for s=find(sel>0)'
+        y=V1_FG(s).spikes(tt).n(2:end-1)';
+        %yh=V1_FG(s).spikes(1).n(2:end-1);
+        Avg(tt).y = [Avg(tt).y; y];
+        yb = mean(y(t>-0.150 & t<0));
+        %yhb = yh-mean(yh(t>-0.170 & t<-0.070));
+        Avg(tt).yb = [Avg(tt).yb; yb];
+        %yn = yb ./ max(yhb(t>0 & t<0.1));
+        %Avg(tt).yn = [Avg(tt).yn; yn];
+    end
+end
+
+bl=[];
+for i=1:length(Avg)
+    bl=[bl Avg(i).yb];
+end
+
+pk=[];
+for i=1:sum(sel)
+    sy=smooth(Avg(1).y(i,:),7);
+    pk=[pk; max(sy(t>0 & t<0.080))];
+end
+
+for tt=[1:4,7,10:12]
+    for s=1:sum(sel)
+        sbl = mean(bl(s,[1:3 5:8]),2);
+        spk = pk(s);
+        Avg(tt).yn(s,:) = (Avg(tt).y(s,:) - sbl)./(spk-sbl) ;
+    end
+end
+
+ms_win = [...
+    -0.064 -0.034   -0.024  0.126  ; ...
+    0.050  0.080    0.090  0.240  ; ...
+    0.150  0.180    0.190  0.340  ; ...
+    ];
+
+sbin1a = find( (t>=ms_win(1,1) & t<ms_win(1,2))>0 );
+sbin2a = find( (t>=ms_win(2,1) & t<ms_win(2,2))>0 );
+sbin3a = find( (t>=ms_win(3,1) & t<ms_win(3,2))>0 );
+sbin1b = find( (t>=ms_win(1,3) & t<ms_win(1,4))>0 );
+sbin2b = find( (t>=ms_win(2,3) & t<ms_win(2,4))>0 );
+sbin3b = find( (t>=ms_win(3,3) & t<ms_win(3,4))>0 );
+
+clear Y
+for tt=[1:4,7,10:12]
+    Y{tt} = nanmean(Avg(tt).yn,1);
+    YS{tt} = smooth(Y{tt},smw);
+    Y2{tt} = YS{tt};
+end
+
+%% Figure/Ground plots ====================================================
+fprintf('FG-MS interaction plots, used in SUPP FIGURE 6F-I\n')
+load(fullfile(fld.data,'Hardcoded_SOA_FG_sel.mat'));
+
+t = V1_FG(1).spikes(1).bin(2:end-1); clear diff
+smoothing_window_ms = 10;
+smw = (smoothing_window_ms/1000)./mean(diff(t));
+
+
+figure('Position',[50 50 1800 1000]);
+subplot(2,6,1:2);hold on;
+plot(t,smooth(nanmean(Avg(2).yn,1),smw),'Color',[0 0.4 0],'LineWidth',2)
+plot(t,smooth(nanmean(Avg(3).yn,1),smw),'Color',[0.2 0 0.8],'LineWidth',2)
+legend({'Figure','Ground'},'Location','northwest');
+set(gca,'xlim',[-0.05 0.35],'ylim',[-.1 1]);
+title([selstring ': F&G responses'], 'interpreter', 'none');
+text(0.27,-0.02,['N = ' num2str(N)],'fontsize',12);
+
+subplot(2,6,7:8);hold on;
+area(t,smooth(nanmean(Avg(2).yn,1)-nanmean(Avg(3).yn,1),smw),...
+    'FaceColor',[0.8 0.8 0.8])
+legend({'Figure-Ground'},'Location','northwest');
+set(gca,'xlim',[-0.05 0.35],'ylim',[-.075 0.15]);
+title([selstring ': F-G'], 'interpreter', 'none');
+text(0.27,-0.05,['N = ' num2str(N)],'fontsize',12);
+
+% F/G interaction with MS 150 ms -----------------------------------------
+LC={[0 0.4 0],[0 0.8 0.2],[0 0 0.6],[0.2 0.8 0.8]};
+subplot(2,6,3:4); hold on;
+ci=0;
+for tt=[2,11,3,12]
+    ci=ci+1;
+    plot(t,smooth(Y2{tt},smw),'Color',LC{ci},'LineWidth',2)
+end
+legend({'FIG','FIG MS','GND','GND MS'},'Location','northeast');
+set(gca,'xlim',[-0.05 0.35],'ylim',[-.1 1]);
+title('F-G and MS@150ms', 'interpreter', 'none');
+
+for recompose_plots=1
+    y=nanmean(Avg(11).yn,1)-nanmean(Avg(2).yn,1);
+    ynan = y; ynan(sbin3a) = nan;
+    y2=smooth(ynan,smw);
+    y2(sbin3a)=y(sbin3a);
+    yy=nanmean(Avg(12).yn,1)-nanmean(Avg(3).yn,1);
+    yynan = yy; yynan(sbin3a) = nan;
+    yy2=smooth(yynan,smw);
+    yy2(sbin3a)=yy(sbin3a);
+end
+subplot(2,6,9:10);hold on;
+area(t,y2,'FaceColor',LC{1})
+legend({'FIG MS - NoMS'},'Location','southwest');
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[0.0 0.35],'ylim',[-0.2 0.25]);
+title('F-G and MS@150ms', 'interpreter', 'none');
+
+subplot(2,6,11:12);hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'GND MS - NoMS'},'Location','southwest');
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[0.0 0.35],'ylim',[-0.2 0.25]);
+title('F-G and MS@150ms', 'interpreter', 'none');
+
+% effect size
+FGMS = [ ...
+    sum(Avg(11).yn(:,sbin3a),2)./length(sbin3a) - ...
+    sum(Avg(2).yn(:,sbin3a),2)./length(sbin3a)...
+    sum(Avg(12).yn(:,sbin3a),2)./length(sbin3a) - ...
+    sum(Avg(3).yn(:,sbin3a),2)./length(sbin3a)...
+    sum(Avg(11).yn(:,sbin3b),2)./length(sbin3b) - ...
+    sum(Avg(2).yn(:,sbin3b),2)./length(sbin3b)...
+    sum(Avg(12).yn(:,sbin3b),2)./length(sbin3b) - ...
+    sum(Avg(3).yn(:,sbin3b),2)./length(sbin3b)];
+
+mFGMS = nanmean(FGMS,1);
+semFGMS = nanstd(FGMS)./sqrt(size(FGMS,1));
+subplot(2,6,5);hold on;
+bar(1,mFGMS(1), 'FaceColor',LC{1});
+bar(2,mFGMS(2), 'FaceColor',LC{3});
+errorbar(1:2,mFGMS(1:2),semFGMS(1:2),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 2.5],'xtick',[1,2],...
+    'xticklabel',{'Fig exc','Gnd exc'});
+title('MS effect @150ms', 'interpreter', 'none');
+
+subplot(2,6,6);hold on;
+bar(1,mFGMS(3), 'FaceColor',LC{1});
+bar(2,mFGMS(4), 'FaceColor',LC{3});
+errorbar(1:2,mFGMS(3:4),semFGMS(3:4),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 2.5],'xtick',[1,2],...
+    'xticklabel',{'Fig sup','Gnd sup'});
+title('MS effect @150ms', 'interpreter', 'none');
+
+%% MS timing plots ========================================================
+fprintf('FG-MS SOA plots\n')
+LC={[0 0 0],[0 0.4 0],[0.8 0 0],[0 0 0.6]};
+figure('Position',[50 50 1800 1000]);
+subplot(5,4,[1 5 9])
+hold on;
+ci=0;
+for tt=[1 4 7 10]
+    ci=ci+1;
+    plot(t,Y2{tt},'Color',LC{ci},'LineWidth',2)
+end
+legend({'no MS','-50ms','50ms','150ms'});
+set(gca,'xlim',[-0.1 0.35]);
+title([selstring ': MS-SOA effect'], 'interpreter', 'none');
+text(0.25,-0.4,['N = ' num2str(N)],'fontsize',12);
+
+subplot(5,4,[3 7 11])
+hold on;
+ci=0;
+for tt=[1 4 7 10]
+    ci=ci+1;
+    plot(t,Y2{tt},'Color',LC{ci},'LineWidth',2)
+end
+legend({'no MS','-50ms','50ms','150ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+yy=nanmean(Avg(4).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin1a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin1a)=yy(sbin1a);
+YY{1}=yy2;
+
+subplot(5,4,2)
+hold on;
+area(t,yy2,'FaceColor',LC{2})
+legend({'-50ms'});
+YLIM=get(gca,'ylim');
+plot([ms_win(1,1) ms_win(1,1)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(1,2) ms_win(1,2)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(1,3) ms_win(1,3)],[YLIM(1) YLIM(2)],'k--');
+plot([ms_win(1,4) ms_win(1,4)],[YLIM(1) YLIM(2)],'k--');
+set(gca,'xlim',[-0.1 0.35]);
+
+subplot(5,4,4)
+hold on;
+area(t,yy2,'FaceColor',LC{2})
+legend({'-50ms'});
+plot([ms_win(1,1) ms_win(1,1)],[-1 1],'k-');
+plot([ms_win(1,2) ms_win(1,2)],[-1 1],'k-');
+plot([ms_win(1,3) ms_win(1,3)],[-1 1],'k--');
+plot([ms_win(1,4) ms_win(1,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(7).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin2a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin2a)=yy(sbin2a);
+YY{2}=yy2;
+
+subplot(5,4,6)
+hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'50ms'});
+YLIM=get(gca,'ylim');
+plot([ms_win(2,1) ms_win(2,1)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(2,2) ms_win(2,2)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(2,3) ms_win(2,3)],[YLIM(1) YLIM(2)],'k--');
+plot([ms_win(2,4) ms_win(2,4)],[YLIM(1) YLIM(2)],'k--');
+set(gca,'xlim',[-0.1 0.35]);
+
+subplot(5,4,8)
+hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'50ms'});
+plot([ms_win(2,1) ms_win(2,1)],[-1 1],'k-');
+plot([ms_win(2,2) ms_win(2,2)],[-1 1],'k-');
+plot([ms_win(2,3) ms_win(2,3)],[-1 1],'k--');
+plot([ms_win(2,4) ms_win(2,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(10).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin3a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin3a)=yy(sbin3a);
+YY{3}=yy2;
+
+subplot(5,4,10)
+hold on;
+area(t,yy2,'FaceColor',LC{4})
+legend({'150ms'});
+YLIM=get(gca,'ylim');
+plot([ms_win(3,1) ms_win(3,1)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[YLIM(1) YLIM(2)],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[YLIM(1) YLIM(2)],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[YLIM(1) YLIM(2)],'k--');
+set(gca,'xlim',[-0.1 0.35]);
+
+subplot(5,4,12)
+hold on;
+area(t,yy2,'FaceColor',LC{4})
+legend({'150ms'});
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+% ------------------------------------------------------------------
+subplot(5,4,[13,14,17,18]);
+hold on;
+plot(t+0.060,YY{1},'Color',LC{2},'LineWidth',2)
+plot(t-0.050,YY{2},'Color',LC{3},'LineWidth',2)
+plot(t-0.150,YY{3},'Color',LC{4},'LineWidth',2)
+set(gca,'xlim',[-0.1 0.2],'ylim',[-0.3 5]);
+title([selstring ': MS-SOA ALIGNED to MS'], 'interpreter', 'none');
+text(-0.075,1,['N = ' num2str(N)],'fontsize',12);
+
+MS_SOA = [sum(Avg(4).yn(:,sbin1a),2)./length(sbin1a) - sum(Avg(1).yn(:,sbin1a),2)./length(sbin1a) ...
+    sum(Avg(7).yn(:,sbin2a),2)./length(sbin2a) - sum(Avg(1).yn(:,sbin2a),2)./length(sbin2a) ...
+    sum(Avg(10).yn(:,sbin3a),2)./length(sbin3a) - sum(Avg(1).yn(:,sbin3a),2)./length(sbin3a) ...
+    sum(Avg(4).yn(:,sbin1b),2)./length(sbin1b) - sum(Avg(1).yn(:,sbin1b),2)./length(sbin1b) ...
+    sum(Avg(7).yn(:,sbin2b),2)./length(sbin2b) - sum(Avg(1).yn(:,sbin2b),2)./length(sbin2b) ...
+    sum(Avg(10).yn(:,sbin3b),2)./length(sbin3b) - sum(Avg(1).yn(:,sbin3b),2)./length(sbin3b)];
+
+mMS_SOA = nanmean(MS_SOA);
+semFGMS = nanstd(MS_SOA)./sqrt(size(MS_SOA,1));
+
+subplot(5,4,[15,19]);
+hold on
+bar(1,mMS_SOA(1), 'FaceColor',LC{2});
+bar(2,mMS_SOA(2), 'FaceColor',LC{3});
+bar(3,mMS_SOA(3), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(1:3),semFGMS(1:3),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Exc. effect', 'interpreter', 'none');
+
+subplot(5,4,[16,20]);
+hold on
+bar(1,mMS_SOA(4), 'FaceColor',LC{2});
+bar(2,mMS_SOA(5), 'FaceColor',LC{3});
+bar(3,mMS_SOA(6), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(4:6),semFGMS(4:6),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Supp. effect', 'interpreter', 'none')
+
+%% MS timing second plot ==================================================
+fprintf('These plots are used for SUPP FIGURE 6A-D\n')
+
+LC={[0 0 0],[0 0.4 0],[0.8 0 0],[0 0 0.6]};
+figure('Position',[50 50 1800 1000]);
+
+subplot(3,3,1); hold on;
+plot(t,Y2{1},'Color',LC{1},'LineWidth',2)
+plot(t,Y2{4},'Color',LC{2},'LineWidth',2)
+legend({'no MS','-50ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+subplot(3,3,2); hold on;
+plot(t,Y2{1},'Color',LC{1},'LineWidth',2)
+plot(t,Y2{7},'Color',LC{3},'LineWidth',2)
+legend({'no MS','50ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+subplot(3,3,3); hold on;
+plot(t,Y2{1},'Color',LC{1},'LineWidth',2)
+plot(t,Y2{10},'Color',LC{4},'LineWidth',2)
+legend({'no MS','150ms'});
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.2 1])
+title('MS-SOA effect', 'interpreter', 'none');
+text(0.25,-0.1,['N = ' num2str(N)],'fontsize',12);
+
+yy=nanmean(Avg(4).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin1a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin1a)=yy(sbin1a);
+YY{1}=yy2;
+
+subplot(3,3,4); hold on;
+area(t,yy2,'FaceColor',LC{2})
+legend({'-50ms'});
+plot([ms_win(1,1) ms_win(1,1)],[-1 1],'k-');
+plot([ms_win(1,2) ms_win(1,2)],[-1 1],'k-');
+plot([ms_win(1,3) ms_win(1,3)],[-1 1],'k--');
+plot([ms_win(1,4) ms_win(1,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(7).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin2a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin2a)=yy(sbin2a);
+YY{2}=yy2;
+
+subplot(3,3,5); hold on;
+area(t,yy2,'FaceColor',LC{3})
+legend({'50ms'});
+plot([ms_win(2,1) ms_win(2,1)],[-1 1],'k-');
+plot([ms_win(2,2) ms_win(2,2)],[-1 1],'k-');
+plot([ms_win(2,3) ms_win(2,3)],[-1 1],'k--');
+plot([ms_win(2,4) ms_win(2,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+yy=nanmean(Avg(10).yn,1)-nanmean(Avg(1).yn,1);
+yynan = yy; yynan(sbin3a) = nan;
+yy2=smooth(yynan,smw);
+yy2(sbin3a)=yy(sbin3a);
+YY{3}=yy2;
+
+subplot(3,3,6); hold on;
+area(t,yy2,'FaceColor',LC{4})
+legend({'150ms'});
+plot([ms_win(3,1) ms_win(3,1)],[-1 1],'k-');
+plot([ms_win(3,2) ms_win(3,2)],[-1 1],'k-');
+plot([ms_win(3,3) ms_win(3,3)],[-1 1],'k--');
+plot([ms_win(3,4) ms_win(3,4)],[-1 1],'k--');
+set(gca,'xlim',[-0.1 0.35],'ylim',[-0.3 0.4]);
+
+subplot(3,3,7); hold on;
+plot([-1 1],[0,0],'k');
+plot(t+0.060,YY{1},'Color',LC{2},'LineWidth',2)
+plot(t-0.050,YY{2},'Color',LC{3},'LineWidth',2)
+plot(t-0.150,YY{3},'Color',LC{4},'LineWidth',2)
+set(gca,'xlim',[-0.1 0.2],'ylim',[-0.3 1]);
+title([selstring ': MS-SOA ALIGNED to MS'], 'interpreter', 'none');
+
+MS_SOA = [sum(Avg(4).yn(:,sbin1a),2)./length(sbin1a) - ...
+    sum(Avg(1).yn(:,sbin1a),2)./length(sbin1a) ...
+    sum(Avg(7).yn(:,sbin2a),2)./length(sbin2a) - ...
+    sum(Avg(1).yn(:,sbin2a),2)./length(sbin2a) ...
+    sum(Avg(10).yn(:,sbin3a),2)./length(sbin3a) - ...
+    sum(Avg(1).yn(:,sbin3a),2)./length(sbin3a) ...
+    sum(Avg(4).yn(:,sbin1b),2)./length(sbin1b) - ...
+    sum(Avg(1).yn(:,sbin1b),2)./length(sbin1b) ...
+    sum(Avg(7).yn(:,sbin2b),2)./length(sbin2b) - ...
+    sum(Avg(1).yn(:,sbin2b),2)./length(sbin2b) ...
+    sum(Avg(10).yn(:,sbin3b),2)./length(sbin3b) - ...
+    sum(Avg(1).yn(:,sbin3b),2)./length(sbin3b)];
+
+mMS_SOA = nanmean(MS_SOA);
+semFGMS = nanstd(MS_SOA)./sqrt(size(MS_SOA,1));
+
+subplot(3,3,8); hold on;
+bar(1,mMS_SOA(1), 'FaceColor',LC{2});
+bar(2,mMS_SOA(2), 'FaceColor',LC{3});
+bar(3,mMS_SOA(3), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(1:3),semFGMS(1:3),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Exc. effect', 'interpreter', 'none');
+
+subplot(3,3,9); hold on;
+bar(1,mMS_SOA(4), 'FaceColor',LC{2});
+bar(2,mMS_SOA(5), 'FaceColor',LC{3});
+bar(3,mMS_SOA(6), 'FaceColor',LC{4});
+errorbar(1:3,mMS_SOA(4:6),semFGMS(4:6),'k','linestyle','none','linewidth',2)
+set(gca,'xlim',[0.5 3.5],'xtick',1:3,'xticklabel',{'-50','50','150'});
+title('Supp. effect', 'interpreter', 'none')
+
+%% Statistics SOA =========================================================
+fprintf('...and the corresponding statistics\n')
+
+% Hardcoded selections
+load(fullfile(fld.data,'Hardcoded_SOA_FG_sel.mat'));
+sel=SOA_sel; N=sum(sel);
+clear sbin
+fprintf('\n\n==== SOA STATISTICS ====\n');
+fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+ttail_exc='both'; % right
+ttail_sup='both'; % left
+
+for Collect=1
+    for tt=[1:4,7,10:12]
+        Avg(tt).y=[];
+        Avg(tt).yb=[];
+        Avg(tt).yn=[];
+        t = V1_FG(1).spikes(1).bin(2:end-1);
+        for s=find(sel>0)'
+            y=V1_FG(s).spikes(tt).n(2:end-1)';
+            Avg(tt).y = [Avg(tt).y; y];
+            yb = mean(y(t>-0.150 & t<0));
+            Avg(tt).yb = [Avg(tt).yb; yb];
+        end
+    end
+    bl=[]; for i=1:length(Avg); bl=[bl Avg(i).yb]; end
+    pk=[];
+    for i=1:sum(sel)
+        sy=smooth(Avg(1).y(i,:),7);
+        pk=[pk; max(sy(t>0 & t<0.080))];
+    end
+    for tt=[1:4,7,10:12]
+        for s=1:sum(sel)
+            sbl = mean(bl(s,[1:3 5:8]),2);
+            spk = pk(s);
+            Avg(tt).yn(s,:) = (Avg(tt).y(s,:) - sbl)./(spk-sbl) ;
+        end
+    end
+    ms_win = [...
+        -0.064 -0.034   -0.024  0.136  ; ...
+        0.050  0.080    0.090  0.250  ; ...
+        0.150  0.180    0.190  0.350  ; ...
+        ];
+    for mt=1:3
+        for w=1:2
+            sbin{mt,w} = find( (t>=ms_win(mt,2*(w-1)+1) & ...
+                t<ms_win(mt,2*(w-1)+2)>0) );
+        end
+    end
+end
+
+MS_SOA = [...
+    sum(Avg(4).yn(:,sbin{1,1}),2)./length(sbin{1,1}) - ...
+    sum(Avg(1).yn(:,sbin{1,1}),2)./length(sbin{1,1}) ...
+    sum(Avg(7).yn(:,sbin{2,1}),2)./length(sbin{2,1}) - ...
+    sum(Avg(1).yn(:,sbin{2,1}),2)./length(sbin{2,1}) ...
+    sum(Avg(10).yn(:,sbin{3,1}),2)./length(sbin{3,1}) - ...
+    sum(Avg(1).yn(:,sbin{3,1}),2)./length(sbin{3,1}) ...
+    sum(Avg(4).yn(:,sbin{1,2}),2)./length(sbin{1,2}) - ...
+    sum(Avg(1).yn(:,sbin{1,2}),2)./length(sbin{1,2}) ...
+    sum(Avg(7).yn(:,sbin{2,2}),2)./length(sbin{2,2}) - ...
+    sum(Avg(1).yn(:,sbin{2,2}),2)./length(sbin{2,2}) ...
+    sum(Avg(10).yn(:,sbin{3,2}),2)./length(sbin{3,2}) - ...
+    sum(Avg(1).yn(:,sbin{3,2}),2)./length(sbin{3,2})  ];
+
+for mt = 1:3
+    SOA(mt).Exc.val = MS_SOA(:,mt);
+    [SOA(mt).Exc.H,SOA(mt).Exc.p, SOA(mt).Exc.ci, SOA(mt).Exc.stats] = ...
+        ttest(SOA(mt).Exc.val,0,'tail',ttail_exc);
+    fprintf(['\nMicrostim induced excitation @time ' num2str(mt) ':\n' ...
+        't(' num2str(SOA(mt).Exc.stats.df) ') = ' num2str(SOA(mt).Exc.stats.tstat) ...
+        ', p = ' num2str(SOA(mt).Exc.p) '\n']);
+
+    SOA(mt).Sup.val = MS_SOA(:,3+mt);
+    [SOA(mt).Sup.H,SOA(mt).Sup.p, SOA(mt).Sup.ci, SOA(mt).Sup.stats] = ...
+        ttest(SOA(mt).Sup.val,0,'tail',ttail_sup);
+    fprintf(['\nMicrostim induced suppression @time ' num2str(mt) ':\n' ...
+        't(' num2str(SOA(mt).Sup.stats.df) ') = ' num2str(SOA(mt).Sup.stats.tstat) ...
+        ', p = ' num2str(SOA(mt).Sup.p) '\n']);
+end
+
+[SOA(4).Exc.p,SOA(4).Exc.ANOVA,SOA(4).Exc.stats] = ...
+    anova1(MS_SOA(:,1:3),{'-58','+50','+150'});
+[SOA(4).Exc.MultComp.c,SOA(4).Exc.MultComp.m,SOA(4).Exc.MultComp.h] = ...
+    multcompare(SOA(4).Exc.stats);
+SOA(4).Exc.MultComp.p = SOA(4).Exc.MultComp.c(:,6)';
+
+[SOA(4).Sup.p,SOA(4).Sup.ANOVA,SOA(4).Sup.stats] = ...
+    anova1(MS_SOA(:,4:6),{'-58','+50','+150'});
+[SOA(4).Sup.MultComp.c,SOA(4).Sup.MultComp.m,SOA(4).Sup.MultComp.h] = ...
+    multcompare(SOA(4).Sup.stats);
+SOA(4).Sup.MultComp.p = SOA(4).Sup.MultComp.c(:,6)';
+
+fprintf(['\nTiming dependence of excitation effect:\n' ...
+    'ANOVA: F(' num2str(SOA(4).Exc.ANOVA{2,3}) ',' ...
+    num2str(SOA(4).Exc.ANOVA{3,3}) ') = ' ...
+    num2str(SOA(4).Exc.ANOVA{2,5}) ', p = ' num2str(SOA(4).Exc.p) '\n']);
+fprintf(['Multiple comparisons, p-values ['...
+    num2str(SOA(4).Exc.MultComp.p(1)) ' ' ...
+    num2str(SOA(4).Exc.MultComp.p(2)) ' ' ...
+    num2str(SOA(4).Exc.MultComp.p(3)) ']\n']);
+fprintf(['\nTiming dependence of suppression effect:\n' ...
+    'ANOVA: F(' num2str(SOA(4).Sup.ANOVA{2,3}) ',' ...
+    num2str(SOA(4).Sup.ANOVA{3,3}) ') = ' ...
+    num2str(SOA(4).Sup.ANOVA{2,5}) ', p = ' num2str(SOA(4).Sup.p) '\n']);
+fprintf(['Multiple comparisons, p-values ['...
+    num2str(SOA(4).Sup.MultComp.p(1)) ' ' ...
+    num2str(SOA(4).Sup.MultComp.p(2)) ' ' ...
+    num2str(SOA(4).Sup.MultComp.p(3)) ']\n']);
+
+%% Statistics FG-GND ======================================================
+% Hardcoded selections
+load(fullfile(fld.data,'Hardcoded_SOA_FG_sel.mat'));
+sel=FG_sel; N=sum(sel);
+clear sbin
+fprintf('\n\n==== FIGURE-GROUND STATISTICS ====\n');
+fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+ttail_fg='right'; % right
+ttail_exc='right'; % right
+ttail_sup='left'; % left
+
+for Collect=1
+    for tt=[1:4,7,10:12]
+        Avg(tt).y=[];
+        Avg(tt).yb=[];
+        Avg(tt).yn=[];
+        t = V1_FG(1).spikes(1).bin(2:end-1);
+        for s=find(sel>0)'
+            y=V1_FG(s).spikes(tt).n(2:end-1)';
+            Avg(tt).y = [Avg(tt).y; y];
+            yb = mean(y(t>-0.150 & t<0));
+            Avg(tt).yb = [Avg(tt).yb; yb];
+        end
+    end
+    bl=[]; for i=1:length(Avg); bl=[bl Avg(i).yb]; end
+    pk=[];
+    for i=1:sum(sel)
+        sy=smooth(Avg(1).y(i,:),7);
+        pk=[pk; max(sy(t>0 & t<0.080))];
+    end
+    for tt=[1:4,7,10:12]
+        for s=1:sum(sel)
+            sbl = mean(bl(s,[1:3 5:8]),2);
+            spk = pk(s);
+            Avg(tt).yn(s,:) = (Avg(tt).y(s,:) - sbl)./(spk-sbl) ;
+        end
+    end
+    ms_win = [...
+        -0.064 -0.034   -0.024  0.136  ; ...
+        0.050  0.080    0.090  0.250  ; ...
+        0.150  0.180    0.190  0.350  ; ...
+        ];
+    fg_win = [0.150 0.350];
+    for mt=1:3
+        for w=1:2
+            sbin{mt,w} = find( (t>=ms_win(mt,2*(w-1)+1) & ...
+                t<ms_win(mt,2*(w-1)+2)>0) );
+        end
+    end
+    fgbin = find( (t>=fg_win(1) & t<fg_win(2)>0) );
+end
+
+
+FG_mod = sum( Avg(2).yn(:,fgbin)-Avg(3).yn(:,fgbin) ,2)./length(fgbin);
+[FG.Mod.H,FG.Mod.p,FG.Mod.ci,FG.Mod.stats] = ...
+    ttest(FG_mod,0,'tail',ttail_fg);
+fprintf(['\nFigure-Ground modulation:\n' ...
+    't(' num2str(FG.Mod.stats.df) ') = ' num2str(FG.Mod.stats.tstat) ...
+    ', p = ' num2str(FG.Mod.p) '\n']);
+fprintf('---------\n');
+
+MS_FG = [...
+    sum(Avg(11).yn(:,sbin{3,1}),2)./length(sbin{3,1}) - ...
+    sum(Avg(2).yn(:,sbin{3,1}),2)./length(sbin{3,1}) ...
+    sum(Avg(12).yn(:,sbin{3,1}),2)./length(sbin{3,1}) - ...
+    sum(Avg(3).yn(:,sbin{3,1}),2)./length(sbin{3,1}) ...
+    sum(Avg(11).yn(:,sbin{3,2}),2)./length(sbin{3,2}) - ...
+    sum(Avg(2).yn(:,sbin{3,2}),2)./length(sbin{3,2}) ...
+    sum(Avg(12).yn(:,sbin{3,2}),2)./length(sbin{3,2}) - ...
+    sum(Avg(3).yn(:,sbin{3,2}),2)./length(sbin{3,2}) ];
+
+FG.Exc.val = MS_FG(:,1);
+[FG.Exc.H,FG.Exc.p,FG.Exc.ci,FG.Exc.stats] = ...
+    ttest(FG.Exc.val,0,'tail',ttail_exc);
+fprintf(['\nMicrostim induced excitation FIG:\n' ...
+    't(' num2str(FG.Exc.stats.df) ') = ' num2str(FG.Exc.stats.tstat) ...
+    ', p = ' num2str(FG.Exc.p) '\n']);
+
+GND.Exc.val = MS_FG(:,2);
+[GND.Exc.H,GND.Exc.p,GND.Exc.ci,GND.Exc.stats] = ...
+    ttest(GND.Exc.val,0,'tail',ttail_exc);
+fprintf(['\nMicrostim induced excitation GND:\n' ...
+    't(' num2str(GND.Exc.stats.df) ') = ' num2str(GND.Exc.stats.tstat) ...
+    ', p = ' num2str(GND.Exc.p) '\n']);
+
+FG.Sup.val = MS_FG(:,3);
+[FG.Sup.H,FG.Sup.p,FG.Sup.ci,FG.Sup.stats] = ...
+    ttest(FG.Sup.val,0,'tail',ttail_sup);
+fprintf(['\nMicrostim induced suppression FIG:\n' ...
+    't(' num2str(FG.Sup.stats.df) ') = ' num2str(FG.Sup.stats.tstat) ...
+    ', p = ' num2str(FG.Sup.p) '\n']);
+
+GND.Sup.val = MS_FG(:,4);
+[GND.Sup.H,GND.Sup.p,GND.Sup.ci,GND.Sup.stats] = ...
+    ttest(GND.Sup.val,0,'tail',ttail_sup);
+fprintf(['\nMicrostim induced suppression GND:\n' ...
+    't(' num2str(GND.Sup.stats.df) ') = ' num2str(GND.Sup.stats.tstat) ...
+    ', p = ' num2str(GND.Sup.p) '\n']);
+
+[FgGnd.Exc.p,FgGnd.Exc.ANOVA,FgGnd.Exc.stats] = ...
+    anova1([FG.Exc.val GND.Exc.val],{'FIG','GND'});
+[FgGnd.Sup.p,FgGnd.Sup.ANOVA,FgGnd.Sup.stats] = ...
+    anova1([FG.Sup.val GND.Sup.val],{'FIG','GND'});
+
+fprintf(['\nFig-Gnd dependence of excitation effect:\n' ...
+    'ANOVA: F(' num2str(FgGnd.Exc.ANOVA{2,3}) ',' ...
+    num2str(FgGnd.Exc.ANOVA{2,3}) ') = ' ...
+    num2str(FgGnd.Exc.ANOVA{3,5}) ', p = ' num2str(FgGnd.Exc.p) '\n']);
+fprintf(['\nFig-Gnd dependence of suppression effect:\n' ...
+    'ANOVA: F(' num2str(FgGnd.Sup.ANOVA{2,3}) ',' ...
+    num2str(FgGnd.Sup.ANOVA{2,3}) ') = ' ...
+    num2str(FgGnd.Sup.ANOVA{3,5}) ', p = ' num2str(FgGnd.Sup.p) '\n']);

+ 374 - 0
SCRIPTS/FUNCTIONS/SACCADE_Analysis.m

@@ -0,0 +1,374 @@
+%% SACCADE_Analysis.m
+EYE_DataFile = fullfile(fld.data,'EYE.mat');
+load(EYE_DataFile)
+
+%% Words meaning ----------------------------------------------------------
+%1-4 Homogenous Texture [noMS SOA1 SOA2 SOA3]
+%5-8 Figure position #1 [noMS SOA1 SOA2 SOA3]
+%9-12 Figure position #2 [noMS SOA1 SOA2 SOA3]
+
+%% Process the data -------------------------------------------------------
+wNoMs = [1 5 9]; wWithMS= [4 8 12];
+
+fixations.noMS.X = []; fixations.noMS.Y = [];
+fixations.withMS.X = []; fixations.withMS.Y = [];
+fixations.noMS.D = []; fixations.withMS.D = [];
+fixations.noMS.V = []; fixations.withMS.V = [];
+fixations.noMS.microsacc = []; fixations.withMS.microsacc = [];
+fixations.noMS.microsaccn = []; fixations.withMS.microsaccn = [];
+
+TANKS_DATA = NEW_PERFORMANCES.FEEDBACK.TANKS;
+for tank = 1:size(TANKS_DATA,2)
+    performance = TANKS_DATA(tank).newPerformance;
+    wordData    = TANKS_DATA(tank).oldTrials(:,7);
+    
+    % ----- NO MICROSTIMULATION ------------
+    indNoMS = ismember(wordData,wNoMs) & performance == 1;
+    fixations.noMS.X = [fixations.noMS.X; ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indNoMS,1))];
+    fixations.noMS.Y = [fixations.noMS.Y; ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indNoMS,2))];
+    fixations.noMS.D = [fixations.noMS.D; ...
+        nanmean(TANKS_DATA(tank).gazeAmplitude(indNoMS,1))];
+    
+    mEyeShift=[]; cEyeShift=[]; sdEyePos=[]; 
+    sz_micsacc = []; num_microsacc = [];
+    for tr=find(indNoMS==1)'
+        ev = TANKS_DATA(tank).gazePos{tr};
+        if ~isempty(ev)
+            mEyeShift = [mEyeShift; ...
+                nanmean(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            cEyeShift = [cEyeShift; ...
+                sum(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            sdEyePos = [sdEyePos; std(ev(:,1)) std(ev(:,2)) tank tr];
+            
+            % get microsaccades
+            micsacc = micsaccdeg([zeros(length(ev),1) ev], Sampf);
+            n_micsacc = size(micsacc,1);
+            if ~isempty(micsacc)
+                sz_micsacc = [sz_micsacc; ...
+                    micsacc(:,4) tank*ones(size(micsacc,1),1) ...
+                    tr*ones(size(micsacc,1),1)...
+                    ]; 
+                num_microsacc=[num_microsacc; n_micsacc];
+            else
+                num_microsacc=[num_microsacc; 0];
+            end
+        end
+    end
+    fixations.noMS.V = [fixations.noMS.V; mEyeShift cEyeShift sdEyePos];
+    fixations.noMS.microsacc = [fixations.noMS.microsacc; sz_micsacc];
+    fixations.noMS.microsaccn = [fixations.noMS.microsaccn; num_microsacc];
+
+    % ----- WITH MICROSTIMULATION ------------
+    indWithMS = ismember(wordData,wWithMS) & performance == 1;
+    fixations.withMS.X = [fixations.withMS.X;  ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indWithMS,1))];
+    fixations.withMS.Y = [fixations.withMS.Y;  ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indWithMS,2))];
+    fixations.withMS.D = [fixations.withMS.D; ...
+        nanmean(TANKS_DATA(tank).gazeAmplitude(indWithMS,1))];
+    
+    mEyeShift=[]; cEyeShift=[]; sdEyePos=[]; 
+    sz_micsacc = []; num_microsacc = [];
+    for tr=find(indWithMS==1)'
+        ev = TANKS_DATA(tank).gazePos{tr};
+        if ~isempty(ev)
+            mEyeShift = [mEyeShift; ...
+                nanmean(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            cEyeShift = [cEyeShift; ...
+                sum(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            sdEyePos = [sdEyePos; ...
+                std(ev(:,1)) std(ev(:,2)) tank tr];
+            
+            % get microsaccades
+            micsacc = micsaccdeg([zeros(length(ev),1) ev], Sampf);
+            n_micsacc = size(micsacc,1);
+            if ~isempty(micsacc)
+                sz_micsacc = [sz_micsacc; ...
+                    micsacc(:,4) tank*ones(size(micsacc,1),1) ...
+                    tr*ones(size(micsacc,1),1)...
+                    ]; 
+                num_microsacc=[num_microsacc; n_micsacc];
+            else
+                num_microsacc=[num_microsacc; 0];
+            end
+        end
+    end
+    fixations.withMS.V = [fixations.withMS.V; mEyeShift cEyeShift sdEyePos];
+    fixations.withMS.microsacc = [fixations.withMS.microsacc; sz_micsacc];
+    fixations.withMS.microsaccn = [fixations.withMS.microsaccn; num_microsacc];
+
+end
+
+TANKS_DATA = NEW_PERFORMANCES.FEEDFORWARD.TANKS;
+for tank = 1:size(TANKS_DATA,2)
+    performance = TANKS_DATA(tank).newPerformance;
+    wordData    = TANKS_DATA(tank).oldTrials(:,7);
+    
+    % ----- NO MICROSTIMULATION ------------
+    indNoMS = ismember(wordData,wNoMs) & performance == 1;
+    fixations.noMS.X = [fixations.noMS.X; ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indNoMS,1))];
+    fixations.noMS.Y = [fixations.noMS.Y; ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indNoMS,2))];
+    fixations.noMS.D = [fixations.noMS.D; ...
+        nanmean(TANKS_DATA(tank).gazeAmplitude(indNoMS,1))];
+    
+    mEyeShift=[]; cEyeShift=[]; sdEyePos=[]; 
+    sz_micsacc = []; num_microsacc = [];
+    for tr=find(indNoMS==1)'
+        ev = TANKS_DATA(tank).gazePos{tr};
+        if ~isempty(ev)
+            mEyeShift = [mEyeShift; ...
+                nanmean(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            cEyeShift = [cEyeShift; ...
+                sum(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            sdEyePos = [sdEyePos; std(ev(:,1)) std(ev(:,2)) tank tr];
+            
+            % get microsaccades
+            micsacc = micsaccdeg([zeros(length(ev),1) ev], Sampf);
+            n_micsacc = size(micsacc,1);
+            if ~isempty(micsacc)
+                sz_micsacc = [sz_micsacc; ...
+                    micsacc(:,4) tank*ones(size(micsacc,1),1) ...
+                    tr*ones(size(micsacc,1),1)...
+                    ]; 
+                num_microsacc=[num_microsacc; n_micsacc];
+            else
+                num_microsacc=[num_microsacc; 0];
+            end
+        end
+    end
+    fixations.noMS.V = [fixations.noMS.V; mEyeShift cEyeShift sdEyePos];
+    fixations.noMS.microsacc = [fixations.noMS.microsacc; sz_micsacc];
+    fixations.noMS.microsaccn = [fixations.noMS.microsaccn; num_microsacc];
+
+    % ----- WITH MICROSTIMULATION ------------
+    indWithMS = ismember(wordData,wWithMS) & performance == 1;
+    fixations.withMS.X = [fixations.withMS.X;  ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indWithMS,1))];
+    fixations.withMS.Y = [fixations.withMS.Y;  ...
+        nanmean(TANKS_DATA(tank).gazeXYCoords(indWithMS,2))];
+    fixations.withMS.D = [fixations.withMS.D; ...
+        nanmean(TANKS_DATA(tank).gazeAmplitude(indWithMS,1))];
+    
+    mEyeShift=[]; cEyeShift=[]; sdEyePos=[]; 
+    sz_micsacc = []; num_microsacc = [];
+    for tr=find(indWithMS==1)'
+        ev = TANKS_DATA(tank).gazePos{tr};
+        if ~isempty(ev)
+            mEyeShift = [mEyeShift; ...
+                nanmean(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            cEyeShift = [cEyeShift; ...
+                sum(sqrt(diff(ev(:,1)).^2 + diff(ev(:,2)).^2))];
+            sdEyePos = [sdEyePos; std(ev(:,1)) std(ev(:,2)) tank tr];
+            
+            % get microsaccades
+            micsacc = micsaccdeg([zeros(length(ev),1) ev], Sampf);
+            n_micsacc = size(micsacc,1);
+            if ~isempty(micsacc)
+                sz_micsacc = [sz_micsacc; ...
+                    micsacc(:,4) tank*ones(size(micsacc,1),1) ...
+                    tr*ones(size(micsacc,1),1)...
+                    ]; 
+                num_microsacc=[num_microsacc; n_micsacc];
+            else
+                num_microsacc=[num_microsacc; 0];
+            end
+        end
+    end
+    fixations.withMS.V = [fixations.withMS.V; mEyeShift cEyeShift sdEyePos];
+    fixations.withMS.microsacc = [fixations.withMS.microsacc; sz_micsacc];
+    fixations.withMS.microsaccn = [fixations.withMS.microsaccn; num_microsacc];
+end
+
+%% Plot fixations X distribution ------------------------------------------
+
+bins = [-0.3:0.01:0.3];
+[cNoMS,xNoMS] = hist(fixations.noMS.X,bins);fNoMS = cNoMS/sum(cNoMS);
+[cWithMS,xWithMS] = hist(fixations.withMS.X,bins);
+fWithMS = cWithMS/sum(cWithMS);
+figure(1);clf;
+subplot(2,2,1);hold all;
+set(gca,'FontSize',12)
+plot(xNoMS,fNoMS,'Color',[0.85 0.18 0.17])
+plot(xWithMS,fWithMS,'Color',[0.35 0.35 0.35])
+xlabel('Average Fixations X')
+ylabel('Frequency')
+legend({'noMS' 'withMS'})
+
+[cNoMS,xNoMS] = hist(fixations.noMS.Y,bins);fNoMS = cNoMS/sum(cNoMS);
+[cWithMS,xWithMS] = hist(fixations.withMS.Y,bins);
+fWithMS = cWithMS/sum(cWithMS);
+subplot(2,2,2);hold all;
+set(gca,'FontSize',12)
+plot(xNoMS,fNoMS,'Color',[0.85 0.18 0.17])
+plot(xWithMS,fWithMS,'Color',[0.35 0.35 0.35])
+xlabel('Average Fixations Y')
+legend({'noMS' 'withMS'})
+
+%% Plot one to one correspondance -----------------------------------------
+subplot(2,2,3)
+hold all;
+
+for ses = 1:length(fixations.noMS.X)
+    plot([1 2],[fixations.noMS.X(ses) fixations.withMS.X(ses)],'-k')
+    scatter(1,fixations.noMS.X(ses),15,[1 0 0])
+    scatter(2,fixations.withMS.X(ses),15,[1 0 0])
+end
+xlim([0.7 2.3])
+set(gca,'XTick',[1 2])
+set(gca,'XTickLabel',{'noMS' 'witMS'})
+
+subplot(2,2,4)
+hold all;
+
+for ses = 1:length(fixations.noMS.Y)
+    plot([1 2],[fixations.noMS.Y(ses) fixations.withMS.Y(ses)],'-k')
+    scatter(1,fixations.noMS.Y(ses),15,[1 0 0])
+    scatter(2,fixations.withMS.Y(ses),15,[1 0 0])
+end
+xlim([0.7 2.3])
+set(gca,'XTick',[1 2])
+set(gca,'XTickLabel',{'noMS' 'witMS'})
+
+%% Plot average amplitude -------------------------------------------------
+f=figure;
+subplot(1,4,1);hold on;
+errorbar([1 2],[nanmean(fixations.noMS.D) nanmean(fixations.withMS.D)],...
+    [nanstd(fixations.noMS.D) nanstd(fixations.withMS.D)],'ks',...
+    'linestyle','none','linewidth',2,'markersize',12,'markerfacecolor','k');
+set(gca, 'xlim',[0 3],'ylim',[0 0.3],'xtick',1:2,'xticklabels',{'no MS','MS'})
+ylabel('Gaze amplitude');
+title('Mean +/- stdev')
+
+subplot(1,4,2:4);hold on;
+[y1,x1]=hist(fixations.noMS.D,100); y1b=y1/sum(y1);
+[y2,x2]=hist(fixations.withMS.D,100); y2b=y2/sum(y2);
+bar(x1,y1b,'r','Edgecolor','none','barwidth',1);
+bar(x2,-y2b,'k','Edgecolor','none','barwidth',1);
+xlabel('Gaze Amplitude')
+ylabel('Frequency')
+legend({'noMS' 'withMS'})
+title('Gaze amplitude distributions')
+
+%% stats on amplitude -----------------------------------------------------
+gazemat = [fixations.noMS.D;fixations.withMS.D];
+group = {[zeros(size(fixations.noMS.D)); ones(size(fixations.withMS.D))]};
+gn={'MS'};
+[P,T,STATS,TERMS]=anovan(gazemat,group)
+
+%% Plot average eyeshifts [averaged per trial] ----------------------------
+f2=figure;
+subplot(2,4,1);hold on;
+errorbar([1 2],[nanmean(fixations.noMS.V(:,1)) nanmean(fixations.withMS.V(:,1))],...
+    [nanstd(fixations.noMS.V(:,1)) nanstd(fixations.withMS.V(:,1))],'ks',...
+    'linestyle','none','linewidth',2,'markersize',12,'markerfacecolor','k');
+set(gca,'xlim',[0 3],'ylim',[0 0.02],'xtick',1:2,'xticklabels',{'no MS','MS'})
+ylabel('Aver. Gaze Shift');
+title('Mean +/- stdev')
+
+subplot(2,4,2:4);hold on;
+[y1,x1]=hist(fixations.noMS.V(:,1),100); y1b=y1/sum(y1);
+[y2,x2]=hist(fixations.withMS.V(:,1),100); y2b=y2/sum(y2);
+bar(x1,y1b,'r','Edgecolor','none','barwidth',1);
+bar(x2,-y2b,'k','Edgecolor','none','barwidth',1);
+xlabel('Aver. Gaze Shifts')
+ylabel('Frequency')
+legend({'noMS' 'withMS'})
+title('Average gaze shift distributions')
+
+%% stats on amplitude -----------------------------------------------------
+gazemat = [fixations.noMS.V(:,1);fixations.withMS.V(:,1)];
+group = {[zeros(size(fixations.noMS.V(:,1))); ...
+    ones(size(fixations.withMS.V(:,1)))]};
+gn={'MS'};
+[P,T,STATS,TERMS]=anovan(gazemat,group)
+
+%% Plot cumulative eyeshifts per trial ------------------------------------
+subplot(2,4,5);hold on;
+errorbar([1 2],[nanmean(fixations.noMS.V(:,2)) ...
+    nanmean(fixations.withMS.V(:,2))],...
+    [nanstd(fixations.noMS.V(:,2)) ...
+    nanstd(fixations.withMS.V(:,2))],'ks',...
+    'linestyle','none','linewidth',2,'markersize',12,...
+    'markerfacecolor','k');
+set(gca,'xlim',[0 3],'ylim',[0 6],'xtick',1:2,'xticklabels',{'no MS','MS'})
+ylabel('Cum. Gaze shift');
+title('Mean +/- stdev')
+
+subplot(2,4,6:8);hold on;
+[y1,x1]=hist(fixations.noMS.V(:,2),100); y1b=y1/sum(y1);
+[y2,x2]=hist(fixations.withMS.V(:,2),100); y2b=y2/sum(y2);
+bar(x1,y1b,'r','Edgecolor','none','barwidth',1);
+bar(x2,-y2b,'k','Edgecolor','none','barwidth',1);
+xlabel('Cum. Gaze Shift')
+ylabel('Frequency')
+legend({'noMS' 'withMS'})
+title('Cumulative gaze shift distributions')
+
+%% stats on amplitude -----------------------------------------------------
+gazemat = [fixations.noMS.V(:,2);fixations.withMS.V(:,2)];
+group = {[zeros(size(fixations.noMS.V(:,2))); ...
+    ones(size(fixations.withMS.V(:,2)))]};
+gn={'MS'};
+[P,T,STATS,TERMS]=anovan(gazemat,group)
+
+%% Plot microsaccades amplitudes and number per trial ---------------------
+figure;
+subplot(2,4,1);hold on;
+errorbar([1 2],[nanmean(fixations.noMS.microsacc(:,1)) ...
+    nanmean(fixations.withMS.microsacc(:,1))],...
+    [nanstd(fixations.noMS.microsacc(:,1)) ...
+    nanstd(fixations.withMS.microsacc(:,1))],'ks',...
+    'linestyle','none','linewidth',2,'markersize',12,'markerfacecolor','k');
+set(gca,'xlim',[0 3],'ylim',[0 0.4],'xtick',1:2,'xticklabel',{'no MS','MS'})
+ylabel('Microsacc amplitude');
+title('Mean +/- stdev')
+
+subplot(2,4,2:4);hold on;
+[y1,x1]=hist(fixations.noMS.microsacc(:,1),100); y1b=y1/sum(y1);
+[y2,x2]=hist(fixations.withMS.microsacc(:,1),100); y2b=y2/sum(y2);
+bar(x1,y1b,'r','Edgecolor','none','barwidth',1);
+bar(x2,-y2b,'k','Edgecolor','none','barwidth',1);
+set(gca,'xlim',[0 0.6],'ylim',[-0.12 0.12]);
+xlabel('Microsaccade amplitude')
+ylabel('Frequency')
+legend({'no MS' 'MS'})
+title('Microsaccade amplitude distributions')
+
+subplot(2,4,5);hold on;
+errorbar([1 2],[nanmean(fixations.noMS.microsaccn(:,1)) ...
+    nanmean(fixations.withMS.microsaccn(:,1))],...
+    [nanstd(fixations.noMS.microsaccn(:,1)) ...
+    nanstd(fixations.withMS.microsaccn(:,1))],'ks',...
+    'linestyle','none','linewidth',2,'markersize',12,'markerfacecolor','k');
+set(gca,'xlim',[0 3],'ylim',[-3 8],'xtick',1:2,'xticklabel',{'no MS','MS'})
+ylabel('# microsacc / trial');
+title('Mean +/- stdev')
+
+subplot(2,4,6:8);hold on;
+[y1,x1]=hist(fixations.noMS.microsaccn(:,1),0:30); y1b=y1/sum(y1);
+[y2,x2]=hist(fixations.withMS.microsaccn(:,1),0:30); y2b=y2/sum(y2);
+bar(x1,y1b,'r','Edgecolor','none','barwidth',1);
+bar(x2,-y2b,'k','Edgecolor','none','barwidth',1);
+set(gca,'xlim',[-1 15]);
+xlabel('# microsaccades per trial')
+ylabel('Frequency')
+legend({'no MS' 'MS'})
+title('Number of microsaccades')
+
+%% stats on microsccades --------------------------------------------------
+% amplitudes
+microsacmat = [fixations.noMS.microsacc(:,1);...
+    fixations.withMS.microsacc(:,1)];
+group = {[zeros(size(fixations.noMS.microsacc(:,1))); ...
+    ones(size(fixations.withMS.microsacc(:,1)))]};
+gn={'MS'}; [P,T,STATS,TERMS]=anovan(microsacmat,group)
+% number
+microsacmat2 = [fixations.noMS.microsaccn(:,1);...
+    fixations.withMS.microsaccn(:,1)];
+group = {[zeros(size(fixations.noMS.microsaccn(:,1))); ...
+    ones(size(fixations.withMS.microsaccn(:,1)))]};
+gn={'MS'}; [P2,T2,STATS2,TERMS2]=anovan(microsacmat2,group)

+ 797 - 0
SCRIPTS/FUNCTIONS/STRAT_FIGURES.m

@@ -0,0 +1,797 @@
+%% Init =================================================================
+% V1MS data file
+V1MS_DataFile = fullfile(fld.data,'V1MS_CAC.mat');
+V4MS_DataFile = fullfile(fld.data,'V4MS_CAC.mat');
+
+% Effect Windows
+EffWin.V1toV4.Exc = [0 0.050];
+EffWin.V1toV4.Sup = [0.050 0.120];
+EffWin.V4toV1.Exc = [0 0.030];
+EffWin.V4toV1.Sup = [0.030 0.150];
+
+%% FIGURE S7C FB ========================================================
+fprintf('\n -- SUPP FIGURE 7C ----------\n');
+fprintf('-- Original FEEDBACK MS EFFECT --')
+
+EffectWindow.exc = EffWin.V4toV1.Exc;
+EffectWindow.sup = EffWin.V4toV1.Sup;
+
+fprintf(['Calculating V1 effect sizes in the following post-stimulation windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+load(V4MS_DataFile)
+V4MS = preProcessV4MS(V4MS,EffectWindow);
+
+FSZ = 12;  
+S = 10; SS = [-0.02 0.05 .15];
+figure(104);
+set(gcf,'Position',[0 0 1600 600])
+subplot(1,4,1:2);hold on;
+for soa = 3
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.15 1.05])
+    YL = ylim;
+    p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+        'EdgeColor','none','FaceColor',[230 220 110]/255);
+    hms = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,soa+1)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),S),'Color',...
+        V4MS.META.COLS(soa+1,:), 'LineWidth',1);
+    hbl = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),'Color',...
+        0*V4MS.META.COLS(1,:),'LineWidth',1);
+    legend([hbl hms],{'no MS' 'MS'})
+    xlabel('Time [s]')
+end
+title('Feedback V4 to V1 (SOA 150ms)')
+
+subplot(1,4,4);hold on;
+set(gca,'FontSize',FSZ)
+ylim([-0.15 0.06])
+YL = ylim;
+p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+    'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10;
+SAOS = [-0.02 0.05 0.15];
+hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V4MS.TIME-SAOS(soa),smooth(-V4MS.CLEAN.AVE(:,1)+...
+        V4MS.CLEAN.AVE(:,soa+1),S)/nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),...
+        'Color',V4MS.META.COLS(soa+1,:),'LineWidth',1);
+    xlim([-0.1 0.2])
+end
+plot(xlim,[0 0],'k:')
+set(gca,'YTick',[-0.1:0.05:0.05])
+set(gca,'XTick',[-0.1:0.1:0.1])
+legend(hds,{'-20ms' '50ms' '150ms'},'Location','SouthWest')
+ylabel('MS - BL');
+xlabel('Time [s]')
+
+% -------
+
+ANOVA_DATA= [];ANOVA_DATA2= [];
+OVER = V4MS.RFDATA(:,5);
+
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V4MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));;
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V4MS.META.COLS(soa+1,:))
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([-0.07 0.002])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Suppression')
+
+subplot(1,4,3);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V4MS.EXCIT_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));;
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V4MS.META.COLS(soa+1,:))  
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.05 0.05])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Excitation')
+
+% stats
+[H,P,CI,STATS] = ttest(ANOVA_DATA2(:,3));
+fprintf(['ORG EXC 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+[H,P,CI,STATS] = ttest(ANOVA_DATA(:,3));
+fprintf(['ORG SUPP 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+
+print_figure('suppfigure7CD' ,[0 0 16 6],fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+%% FIGURE S7A FF ========================================================
+fprintf('\n -- SUPP FIGURE 7A ----------\n');
+fprintf('-- Original FEEDFORWARD MS EFFECT --')
+EffectWindow.exc = EffWin.V1toV4.Exc;
+EffectWindow.sup = EffWin.V1toV4.Sup;
+
+fprintf(['Calculating V1 effect sizes in the following post-stimulation windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+load(V1MS_DataFile)
+V1MS = preProcessV1MS(V1MS,EffectWindow);
+
+S = 10;
+SS = [-0.05 0.05 .15];
+
+figure(105);
+set(gcf,'Position',[0 0 1600 600])
+subplot(1,4,1:2);hold on;
+for soa = 3
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.7 3.4])
+    YL = ylim;p = patch([SS(soa) SS(soa) SS(soa)+0.025 ...
+        SS(soa)+0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+        'EdgeColor','none','FaceColor',[230 220 110]/255);
+    hms = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,soa+1)/nanmax(...
+        smooth(V1MS.CLEAN.AVE(:,1),S)),S),'Color',...
+        V1MS.META.COLS(soa+1,:), 'LineWidth',2);
+    hbl = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,1),S)/nanmax(...
+        smooth(V1MS.CLEAN.AVE(:,1),S)),'Color',...
+        V1MS.META.COLS(1,:)*0,'LineWidth',2);
+    legend([hbl hms],{'no MS' 'MS'})
+    xlabel('Time [s]')
+end
+title('Feedforward V1 to V4 (SOA 150ms)')
+
+ANOVA_DATA = [];ANOVA_DATA2 = [];
+
+subplot(1,4,3);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V1MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(logical(V1MS.CLEAN.UNITSIND))/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([0 1.65])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]');
+title('Excitation');
+
+subplot(1,4,4);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V1MS.SUPPR_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(logical(V1MS.CLEAN.UNITSIND))/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.55 0.05])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]');
+title('Suppression');
+
+% stats
+[H,P,CI,STATS] = ttest(ANOVA_DATA(:,3));
+fprintf(['ORG EXC 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+[H,P,CI,STATS] = ttest(ANOVA_DATA2(:,3));
+fprintf(['ORG SUPP 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+
+print_figure('suppfigure7AB' ,[0 0 16 6],fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+%% Scatter plot of effects sizes against stimulation current ============
+% Import the list of current strengths ===================================
+load(fullfile(fld.data,'STIMCURRENTS.mat'));
+cv1=CURRENT.V1MS; cv4=CURRENT.V4MS;
+
+V4_C = cv4(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)));
+EFFE  = V4MS.EFFECT(3,:);
+V4_ESS = EFFE(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)))/...
+    nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));
+EFFE  = V4MS.EXCIT_EFFECT(3,:);
+V4_ESE = EFFE(~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1)))/...
+    nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));
+
+V1_C = cv1(~isnan(nanmean(V1MS.CLEAN.UNITS(:,:,1),1)));
+EFFE  = V1MS.EFFECT(3,:);
+V1_ESE = EFFE(~isnan(nanmean(V1MS.CLEAN.UNITS(:,:,1),1)))/...
+    nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));
+EFFE  = V1MS.SUPPR_EFFECT(3,:);
+V1_ESS = EFFE(~isnan(nanmean(V1MS.CLEAN.UNITS(:,:,1),1)))/...
+    nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));
+
+figure;
+subplot(1,2,1);hold on
+plot(V1_C,V1_ESE,'ko');
+plot(V4_C,V4_ESE,'ro');
+
+subplot(1,2,2);hold on
+plot(V1_C,V1_ESS,'ko');
+plot(V4_C,V4_ESS,'ro');
+
+%% Stratification =======================================================
+% stratify based on current strengths of microstimulation to equalize the 
+% distributions and of current strengths in both directions.
+% Then recalculate and plot the traces and effect sizes on the stratified
+% subset of the data
+cv1=CURRENT.V1MS; cv4=CURRENT.V4MS;
+
+%% Perform the stratification ===========================================
+fprintf('\n -- SUPP FIGURE 7A,C,E,F insets ----------\n');
+
+% equal number of recordings in each surrent strength bin
+% plot the results and show how many trials are still included
+binw=10; % >>> the binwidth here determines how many trials are included
+% a binwidth of 20 maintains approx. half of the recordings
+%bins=binw/2:binw:(ceil(160/binw)*binw)-binw/2  ;
+bins=0:binw:160  ;
+
+figure;
+subplot(2,2,1);
+f1=hist(cv1,bins);
+bar(bins,f1);
+title(['Original V1 currents (n = ' num2str(sum(f1)) ' )']);
+subplot(2,2,2);
+f4=hist(cv4,bins);
+bar(bins,f4);
+title(['Original V4 currents (n = ' num2str(sum(f4)) ' )']);
+
+% stratify
+cv1i=ones(size(cv1));cv4i=ones(size(cv4));
+for b=1:length(bins)
+    if f1(b)>f4(b)
+        ind = find(cv1>(bins(b)-(binw/2)) & cv1<=(bins(b)+(binw/2))==1);
+        ind2 = ind(randperm(length(ind)));
+        cv1i( ind2( 1:(f1(b)-f4(b)) ) )=0;
+    elseif f1(b)<f4(b)
+        ind = find(cv4>(bins(b)-(binw/2)) & cv4<=(bins(b)+(binw/2))==1);
+        ind2 = ind(randperm(length(ind)));
+        cv4i(ind2(1:(f4(b)-f1(b))))=0;
+    end
+end
+
+subplot(2,2,3);
+f1=hist(cv1(logical(cv1i)),bins);
+bar(bins,f1);
+title(['Stratified V1 currents (n = ' num2str(sum(cv1i)) ' )']);
+subplot(2,2,4);
+f4=hist(cv4(logical(cv4i)),bins);
+bar(bins,f4);
+title(['Stratified V4 currents (n = ' num2str(sum(cv4i)) ' )']);
+ 
+print_figure('suppfigure7_insets' ,[0 0 16 6],fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+%% V1 to V4 init --------------------------------------------------------
+load(V1MS_DataFile);
+
+EffectWindow.exc = EffWin.V1toV4.Exc;
+EffectWindow.sup = EffWin.V1toV4.Sup;
+
+fprintf(['Calculating V4 effect sizes in post-stim windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' ...
+    num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' ...
+    num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+V1MS = preProcessV1MS_S7(V1MS,EffectWindow,cv1i);
+
+%% FIGURE S7E STRAT FF ================================================== 
+fprintf('\n -- SUPP FIGURE 7E ----------\n');
+FSZ = 12; S = 10; SS = [-0.05 0.05 .15];
+figure;hold on;
+for soa = 3
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.7 3.4])
+    YL = ylim;
+    p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none',...
+        'FaceColor',[230 220 110]/255);
+    hms = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,soa+1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),S),'Color',...
+        V1MS.META.COLS(soa+1,:), 'LineWidth',2);
+    hbl = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),'Color',...
+        V1MS.META.COLS(1,:)*0,'LineWidth',2);
+    legend([hbl hms],{'BL' 'MS'})
+    xlabel('Time [s]')
+end
+print_figure('suppfigure7E' ,[0 0 10 6],...
+    fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+% Plot difference between Blank and MS for every SOA. [NOT USED]
+figure(8);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.8 3.45])
+YL = ylim;
+p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+    'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10; SAOS = [-0.05 0.05 0.15]; hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V1MS.TIME-SAOS(soa),smooth(-V1MS.CLEAN.AVE(:,1)+...
+        V1MS.CLEAN.AVE(:,soa+1),S)/nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),...
+        'Color',V1MS.META.COLS(soa+1,:),'LineWidth',2);
+    xlim([-0.1 0.2])
+end
+
+plot(xlim,[0 0],'k:')
+legend(hds,{'-50ms' '50ms' '150ms'},'Location','NorthEast')
+xlabel('Time [s]')
+ANOVA_DATA = [];ANOVA_DATA2 = [];
+
+figure;clf;hold all
+subplot(1,2,1);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V1MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(V1MS.CLEAN.UNITSIND==1 & cv1i==1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([0 1.65])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Excitation V1 to V4');
+
+subplot(1,2,2);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V1MS.SUPPR_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(V1MS.CLEAN.UNITSIND==1 & cv1i==1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.55 0.05])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Suppression V1 to V4');
+
+% stats
+[H,P,CI,STATS] = ttest(ANOVA_DATA2(:,2));
+fprintf(['STRAT EXC 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+[H,P,CI,STATS] = ttest(ANOVA_DATA(:,3));
+fprintf(['STRAT SUPP 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+
+% Statistics for difference in effect size per SOA.
+anova_data = ANOVA_DATA;
+anova_data(isnan(ANOVA_DATA(:,1)),:) = [];
+[P,ANOVATAB,STATS] = anova1(anova_data);
+[c,m,h,names] = multcompare(STATS,'Alpha',10^-6,'CType','tukey-kramer');
+
+anova_data2 = ANOVA_DATA2;
+anova_data2(isnan(ANOVA_DATA2(:,1)),:) = [];
+[P2,ANOVATAB2,STATS2] = anova1(anova_data2);
+[c2,m2,h2,names2] = multcompare(STATS2,'Alpha',10^-6,'CType','tukey-kramer');
+
+%% V4 to V1 init --------------------------------------------------------
+load(V4MS_DataFile);
+
+EffectWindow.exc = EffWin.V4toV1.Exc;
+EffectWindow.sup = EffWin.V4toV1.Sup;
+
+fprintf(['Calculating V1 effect sizes in the following post-stimulation windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' ...
+    num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' ...
+    num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+V4MS = preProcessV4MS_S7(V4MS,EffectWindow,cv4i);
+
+%% FIGURE S7F STRAT FB ================================================== 
+fprintf('\n -- SUPP FIGURE 7F ----------\n');
+
+S = 10; SS = [-0.02 0.05 .15]; figure;
+for soa = 3%1:3;
+    figure (soa+4);clf;hold all;
+    %subplot(1,3,soa);hold on;
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.15 1.05])
+    YL = ylim;p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none',...
+        'FaceColor',[230 220 110]/255);
+    hms = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,soa+1)...
+        /nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),S),'Color',...
+        V4MS.META.COLS(soa+1,:), 'LineWidth',1);
+    hbl = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),'Color',...
+        0*V4MS.META.COLS(1,:),'LineWidth',1);
+    
+    legend([hbl hms],{'BL' 'MS'})
+    xlabel('Time [s]')
+end
+print_figure('suppfigure7F' ,[0 0 10 6],fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+% Difference between MS and Blank MUA for each SOA. [NOT USED]
+figure (8);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.15 0.06])
+YL = ylim;
+p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+    'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10; SAOS = [-0.02 0.05 0.15];
+hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V4MS.TIME-SAOS(soa),smooth(-V4MS.CLEAN.AVE(:,1)+...
+        V4MS.CLEAN.AVE(:,soa+1),S)/nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),...
+        'Color',V4MS.META.COLS(soa+1,:),'LineWidth',1);
+    xlim([-0.1 0.2])
+end
+
+plot(xlim,[0 0],'k:')
+set(gca,'YTick',[-0.1:0.05:0.05])
+set(gca,'XTick',[-0.1:0.1:0.1])
+legend(hds,{'-20ms' '50ms' '150ms'},'Location','SouthWest')
+ylabel('MS - BL');
+xlabel('Time [s]')
+
+% Average Effect Size per SOA [NOT USED]
+ANOVA_DATA= [];ANOVA_DATA2= [];
+OVER = V4MS.RFDATA(:,5);
+
+figure;clf;hold all
+
+subplot(1,2,2);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V4MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(...
+        ~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1))' & logical(cv4i))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V4MS.META.COLS(soa+1,:))
+    
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([-0.06 0.002])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Suppression V4 to V1')
+
+subplot(1,2,1);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V4MS.EXCIT_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(...
+        ~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1))' & logical(cv4i))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V4MS.META.COLS(soa+1,:))
+    
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.05 0.05])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Excitation V4 to V1')
+
+[H,P,CI,STATS] = ttest(ANOVA_DATA2(:,2));
+fprintf(['STRAT EXC 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+[H,P,CI,STATS] = ttest(ANOVA_DATA(:,3));
+fprintf(['STRAT SUPP 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+
+% Statistics for difference in effect size per SOA 
+anova_data2 = ANOVA_DATA2;
+anova_data2(isnan(ANOVA_DATA2(:,1)),:) = [];
+[P2,ANOVATAB2,STATS2] = anova1(anova_data2);
+[c2,m2,h2,names2] = multcompare(STATS2,'Alpha',10^-15,'CType','tukey-kramer');
+
+anova_data = ANOVA_DATA;
+anova_data(isnan(ANOVA_DATA(:,1)),:) = [];
+[P,ANOVATAB,STATS] = anova1(anova_data);
+[c,m,h,names] = multcompare(STATS,'Alpha',10^-15,'CType','tukey-kramer');
+
+%% Extreme cases ========================================================
+% Compare strongest V4 to V1 case wit weakes V1 to V4 case
+cv1=CURRENT.V1MS; cv4=CURRENT.V4MS;
+
+%% Perform the stratification ===========================================
+weakestV1 = min(cv1); strongestV4 = max(cv4);
+
+% select
+cv1i=find(cv1==weakestV1);
+cv1i2=zeros(size(cv1));cv1i2(cv1i)=1;cv1i2=logical(cv1i2);
+cv4i=find(cv4==strongestV4);
+cv4i2=zeros(size(cv4));cv4i2(cv4i)=1;cv4i2=logical(cv4i2);
+
+%% V1 to V4 init --------------------------------------------------------
+load(V1MS_DataFile);
+
+EffectWindow.exc = EffWin.V1toV4.Exc;
+EffectWindow.sup = EffWin.V1toV4.Sup;
+
+fprintf(['Calculating V4 effect sizes in post-stim windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' ...
+    num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' ...
+    num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+V1MS = preProcessV1MS_S7(V1MS,EffectWindow,cv1i);
+
+%% FIGURE S7G STRAT FF ================================================== 
+FSZ = 12; S = 10; SS = [-0.05 0.05 .15];
+figure;hold on;
+for soa = 3
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.3 1.25])
+    YL = ylim;
+    p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none',...
+        'FaceColor',[230 220 110]/255);
+    hms = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,soa+1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),S),'Color',...
+        V1MS.META.COLS(soa+1,:), 'LineWidth',2);
+    hbl = plot(V1MS.TIME,smooth(V1MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),'Color',...
+        V1MS.META.COLS(1,:)*0,'LineWidth',2);
+    legend([hbl hms],{'no MS' 'MS'})
+    xlabel('Time [s]')
+end
+print_figure('suppfigure7G' ,[0 0 10 6],fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+% Plot difference between Blank and MS for every SOA. [NOT USED]
+figure(8);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.8 2])
+YL = ylim;
+p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+    'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10; SAOS = [-0.05 0.05 0.15]; hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V1MS.TIME-SAOS(soa),smooth(-V1MS.CLEAN.AVE(:,1)+...
+        V1MS.CLEAN.AVE(:,soa+1),S)/nanmax(smooth(V1MS.CLEAN.AVE(:,1),S)),...
+        'Color',V1MS.META.COLS(soa+1,:),'LineWidth',2);
+    xlim([-0.1 0.2])
+end
+plot(xlim,[0 0],'k:')
+legend(hds,{'-50ms' '50ms' '150ms'},'Location','NorthEast')
+xlabel('Time [s]')
+
+% Average Effect Size per SOA. [NOT USED]
+ANOVA_DATA = [];ANOVA_DATA2 = [];
+
+figure;clf;hold all
+subplot(1,2,1);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE = V1MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(V1MS.CLEAN.UNITSIND==1 & cv1i2==1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF = nanmean(EFFE_SIG);
+    sEFF = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([0 0.8])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Excitation V1 to V4');
+
+subplot(1,2,2);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2 = V1MS.SUPPR_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(V1MS.CLEAN.UNITSIND==1 & cv1i2==1)/...
+        nanmax(smooth(V1MS.CLEAN.AVE(:,1),S));
+    mEFF2 = nanmean(EFFE_SIG2);
+    sEFF2 = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V1MS.META.COLS(soa+1,:))
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([0 0.4])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Suppression V1 to V4');
+
+% stats
+[H,P,CI,STATS] = ttest(ANOVA_DATA2(:,2));
+fprintf(['STRAT EXC 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+[H,P,CI,STATS] = ttest(ANOVA_DATA(:,3));
+fprintf(['STRAT SUPP 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+
+% Statistics for difference in effect size per SOA.
+anova_data = ANOVA_DATA;
+anova_data(isnan(ANOVA_DATA(:,1)),:) = [];
+[P,ANOVATAB,STATS] = anova1(anova_data);
+[c,m,h,names] = multcompare(STATS,'Alpha',10^-6,'CType','tukey-kramer');
+
+anova_data2 = ANOVA_DATA2;
+anova_data2(isnan(ANOVA_DATA2(:,1)),:) = [];
+[P2,ANOVATAB2,STATS2] = anova1(anova_data2);
+[c2,m2,h2,names2] = multcompare(STATS2,'Alpha',10^-6,'CType','tukey-kramer');
+
+%% V4 to V1 init --------------------------------------------------------
+load(V4MS_DataFile);
+
+EffectWindow.exc = EffWin.V4toV1.Exc;
+EffectWindow.sup = EffWin.V4toV1.Sup;
+
+fprintf(['Calculating V1 effect sizes in the following post-stimulation windows:\n'...
+    'Excitation: ' num2str(EffectWindow.exc(1)*1e3) ' to ' ...
+    num2str(EffectWindow.exc(2)*1e3) ' ms\n'...
+    'Suppression: ' num2str(EffectWindow.sup(1)*1e3) ' to ' ...
+    num2str(EffectWindow.sup(2)*1e3) ' ms\n']);
+
+V4MS = preProcessV4MS_S7(V4MS,EffectWindow,cv4i);
+
+%% FIGURE S7H STRAT FB ================================================== 
+S = 10; SS = [-0.02 0.05 .15]; figure;
+figure (soa+4);clf;hold all;
+for soa = 3
+    set(gca,'FontSize',FSZ)
+    xlim([-0.1 0.35])
+    ylim([-0.25 1.05])
+    YL = ylim;
+    p = patch([SS(soa) SS(soa) SS(soa)+0.025 SS(soa)+0.025],...
+        [YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],'EdgeColor','none',...
+        'FaceColor',[230 220 110]/255);
+    hms = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,soa+1)...
+        /nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),S),'Color',...
+        V4MS.META.COLS(soa+1,:), 'LineWidth',1);
+    hbl = plot(V4MS.TIME,smooth(V4MS.CLEAN.AVE(:,1),S)/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),'Color',...
+        0*V4MS.META.COLS(1,:),'LineWidth',1);
+    
+    legend([hbl hms],{'no MS' 'MS'})
+    xlabel('Time [s]')
+end
+print_figure('suppfigure7H' ,[0 0 10 6],fullfile(fld.figs,'SUPPFIG_7'),save_figs);
+cd(fld.scripts);
+
+% Plot difference between Blank and MS for every SOA. [NOT USED]
+figure (8);clf;hold all;
+set(gca,'FontSize',FSZ)
+ylim([-0.2 0.12])
+YL = ylim;
+p = patch([0 0 0.025 0.025],[YL(1) YL(2) YL(2) YL(1)],0.8*[1 1 1],...
+    'EdgeColor','none','FaceColor',[230 220 110]/255);
+S = 10; SAOS = [-0.02 0.05 0.15];
+hds = [];
+for soa = 1:3
+    hds(end+1) = plot(V4MS.TIME-SAOS(soa),smooth(-V4MS.CLEAN.AVE(:,1)+...
+        V4MS.CLEAN.AVE(:,soa+1),S)/nanmax(smooth(V4MS.CLEAN.AVE(:,1),S)),...
+        'Color',V4MS.META.COLS(soa+1,:),'LineWidth',1);
+    xlim([-0.1 0.2])
+end
+
+plot(xlim,[0 0],'k:')
+set(gca,'YTick',[-0.1:0.05:0.05])
+set(gca,'XTick',[-0.1:0.1:0.1])
+legend(hds,{'-20ms' '50ms' '150ms'},'Location','SouthWest')
+ylabel('MS - BL');
+xlabel('Time [s]')
+
+% Average Effect Size per SOA. [NOT USED]
+ANOVA_DATA= [];ANOVA_DATA2= [];
+OVER = V4MS.RFDATA(:,5);
+
+figure;clf;hold all
+
+subplot(1,2,2);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE  = V4MS.EFFECT(soa,:);
+    EFFE_SIG = EFFE(...
+        ~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1))' & logical(cv4i2))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));
+    mEFF    = nanmean(EFFE_SIG);
+    sEFF    = nanstd(EFFE_SIG)/sqrt(sum(~isnan(EFFE_SIG)));
+    errorbar(soa,mEFF,sEFF,'sk','LineWidth',2);
+    bar(soa,mEFF,'FaceColor',V4MS.META.COLS(soa+1,:))
+    
+    ANOVA_DATA = [ANOVA_DATA EFFE_SIG'];
+end
+ylim([-0.06 0.002])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Suppression V4 to V1')
+
+subplot(1,2,1);hold on;
+set(gca,'FontSize',FSZ)
+for soa = 1:3
+    EFFE2  = V4MS.EXCIT_EFFECT(soa,:);
+    EFFE_SIG2 = EFFE2(...
+        ~isnan(nanmean(V4MS.CLEAN.UNITS(:,:,1),1))' & logical(cv4i2))/...
+        nanmax(smooth(V4MS.CLEAN.AVE(:,1),10));
+    mEFF2    = nanmean(EFFE_SIG2);
+    sEFF2    = nanstd(EFFE_SIG2)/sqrt(sum(~isnan(EFFE_SIG2)));
+    errorbar(soa,mEFF2,sEFF2,'sk','LineWidth',2);
+    bar(soa,mEFF2,'FaceColor',V4MS.META.COLS(soa+1,:))
+    
+    ANOVA_DATA2 = [ANOVA_DATA2 EFFE_SIG2'];
+end
+ylim([-0.05 0.05])
+xlim([0.5 3.5])
+set(gca,'XTick',[1 2 3],'XTickLabel',{'-20' '50' '150'})
+ylabel('Mean Difference')
+xlabel('SOA [ms]')
+title('Excitation V4 to V1')
+
+% stats
+[H,P,CI,STATS] = ttest(ANOVA_DATA2(:,2));
+fprintf(['STRAT EXC 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+[H,P,CI,STATS] = ttest(ANOVA_DATA(:,3));
+fprintf(['STRAT SUPP 150ms: t(' num2str(STATS.df) ') = ' num2str(STATS.tstat) ...
+    ', p = ' num2str(P) '\n']);
+
+% STRAT FIGURE FB            - Statistics for difference in effect size per SOA 
+anova_data2 = ANOVA_DATA2;
+anova_data2(isnan(ANOVA_DATA2(:,1)),:) = [];
+[P2,ANOVATAB2,STATS2] = anova1(anova_data2);
+[c2,m2,h2,names2] = multcompare(STATS2,'Alpha',10^-15,'CType','tukey-kramer');
+
+anova_data = ANOVA_DATA;
+anova_data(isnan(ANOVA_DATA(:,1)),:) = [];
+[P,ANOVATAB,STATS] = anova1(anova_data);
+[c,m,h,names] = multcompare(STATS,'Alpha',10^-15,'CType','tukey-kramer');

+ 96 - 0
SCRIPTS/FUNCTIONS/SUPPORT/Check_IndV1.m

@@ -0,0 +1,96 @@
+PlotAllSelected = false;
+
+%% histograms
+if PlotAllSelected
+    a=find(sel==1)';
+    for sel=a
+        % CHECK: 18
+        figure;
+        % Histograms -------
+        subplot(2,2,1);hold on;
+        mPSTH_nms = mean(psth_nms(sel,2:end-1),1);
+        sePSTH_nms = std(psth_nms(sel,2:end-1),1)./sqrt(length(sel));
+        bar(spk(1).noms_bin(2:end-1),mPSTH_nms,'FaceColor','k','Barwidth',1)
+        plot([msw(1) msw(1)],[-100 100],'b--');
+        plot([msw(2) msw(2)],[-100 100],'b--')
+        set(gca,'xlim',[-0.1 0.350],'ylim',[-0.25 1])
+        title([num2str(sel) '- No MS']);
+
+        subplot(2,2,3);hold on;
+        mPSTH_ms = mean(psth_ms(sel,2:end-1),1);%
+        sePSTH_ms = std(psth_ms(sel,2:end-1),1)./sqrt(length(sel));%
+        bar(spk(1).ms_bin(2:end-1),mPSTH_ms,'FaceColor','r','EdgeColor','r','Barwidth',1)
+        plot([msw(1) msw(1)],[-100 100],'b--');
+        plot([msw(2) msw(2)],[-100 100],'b--')
+        set(gca,'xlim',[-0.1 0.350],'ylim',[-0.25 1])
+        title([num2str(sel) '- MS']);
+
+        % 2 histograms overlaid -----
+        subplot(2,2,2);hold on;
+        plot(spk(1).noms_bin(2:end-1),mPSTH_nms,'Color','k','LineWidth',2)
+        plot(spk(1).ms_bin(2:end-1),mPSTH_ms,'Color','r','LineWidth',2)
+
+        plot([msw(1) msw(1)],[-100 100],'b--');
+        plot([msw(2) msw(2)],[-100 100],'b--')
+        legend({'No MS','MS'})
+        set(gca,'xlim',[-0.05 0.350],'ylim',[-0.25 1])
+        title('No Ms vs. MS');
+
+        % Difference zoomed in ------
+        subplot(2,2,4);hold on;
+        bar(spk(1).noms_bin(2:end-1),mPSTH_ms-mPSTH_nms,'EdgeColor','k','FaceColor','k','Barwidth',1)
+        plot([msw(1) msw(1)],[-100 100],'b--');
+        plot([msw(2) msw(2)],[-100 100],'b--')
+        set(gca,'xlim',[0.100 0.350],'ylim',[-0.2 0.3])
+        title('Difference MS-NoMS');
+    end
+
+    %% raster plots
+    for sel=a
+        figure
+        subplot(1,2,1);hold on;
+        for tr=unique(spk(sel).ms(:,3))'
+            ii=spk(sel).ms(:,3)==tr;
+            plot(spk(sel).ms(ii,1),spk(sel).ms(ii,3),...
+                'ko','MarkerSize',3,'MarkerFaceColor','k');
+        end
+        set(gca,'xlim',[-0.2 0.35],'ylim',[0 tr+1]);
+        title([num2str(sel) '- MS']);
+
+        subplot(1,2,2);hold on;
+        for tr=unique(spk(sel).noms(:,3))'
+            ii=spk(sel).noms(:,3)==tr;
+            plot(spk(sel).noms(ii,1),spk(sel).noms(ii,3),...
+                'ko','MarkerSize',3,'MarkerFaceColor','k');
+        end
+        set(gca,'xlim',[-0.2 0.35],'ylim',[0 tr+1]);
+        title([num2str(sel) '- No MS']);
+    end
+end
+
+%% Figure 2B-C ==========================================================
+fprintf('We used this example for FIGURE 2C-D\n')
+
+% raster plots
+sC=35; sel=35;
+ff=figure;
+subplot(2,1,1);hold on;
+for tr=unique(spk(sel).ms(:,3))'
+    ii=spk(sel).ms(:,3)==tr;
+    plot(spk(sel).ms(ii,1),spk(sel).ms(ii,3),...
+        'ko','MarkerSize',2,'MarkerFaceColor','k');
+end
+set(gca,'xlim',[-0.1 0.35],'ylim',[0 64]);
+title([num2str(sel) '- MS']);
+
+BinSpecs=[-200 5 400]./1000;
+[ms_n, ms_bin] = hist(spk(sel).ms(:,1),...
+    BinSpecs(1):BinSpecs(2):BinSpecs(3));
+ms_n=(ms_n./length(V1_V1(sC).ms_i))/BinSpecs(2);
+
+subplot(2,1,2);hold on;
+bar(ms_bin,ms_n,'FaceColor','k','BarWidth',1)
+set(gca,'xlim',[-0.1 0.35])
+
+print_figure('Fig2B-C' ,[0 0 16 20],fullfile(fld.figs,'FIG_2'),save_figs);
+cd(fld.scripts);

+ 281 - 0
SCRIPTS/FUNCTIONS/SUPPORT/RFpos.m

@@ -0,0 +1,281 @@
+function  RF_INFO=RFpos(DAT, sampf, MP, DegperS, OFF)
+%function  rfpos(MDAT, sampfreq, 0.55, 6.0, SC)
+%
+%A simple function to make receptive field plots
+%In: DAT(samples, channels, orientations)
+%    sampfreq
+%    MP          -  time after first sample that bar crosses midline of
+%                   screen.
+%   DegperS      -  Speed of bar motion in degrees per second
+%
+%   SC           -  Offset from screen center of moving bar
+%Chris van der Togt, jan-2008
+
+% Define data to use
+
+% DAT=INFO.DAT;
+% sampf=INFO.Sampf;
+% MP=INFO.MP;
+% DegperS=INFO.DegperS;
+% OFF.rho=INFO.RFPecc;
+% OFF.angle=INFO.RFPangle;
+
+
+
+
+
+
+numofsamp      = size(DAT,1);  %lengte van de trial
+numofchan      = size(DAT,2);
+numoforient    =  size(DAT,3);
+%DegperS        = 6.0;
+%MP = 0.55; %time (in seconds)when bar crosses center of screen, + 50ms for response onset delay
+
+CHAN = zeros(1,numofchan);
+FMP = zeros(numoforient,numofchan);  %Field hotspot
+CP = FMP;                              %Field center
+FSZ = struct([]);  %field size
+WH = struct([]);
+
+Qtr = round(size(DAT,1)/4);
+%RAD = (-0.5*pi:0.25*pi:1.25*pi)';
+
+[SC.x SC.y] = pol2cart(OFF.angle/180*pi, OFF.rho);
+
+for k = 1:numofchan
+   
+   ERP = squeeze(DAT(:,k,:)); 
+   ERPsm = ERP; %squeeze(smooth(ERP, 10));
+   
+%    ERPsm=nan(size(ERP));
+%    L=size(ERPsm,2);
+%    for j=1:L
+%        temp1=smooth(ERP(:,j),10);
+%        ERPsm(:,j)=temp1;
+%    end
+   
+   FT = fft(ERP);          %fourier transform to frequency plane
+   FT(10:numofsamp,:) = 0;          %remove high frequency components
+   IT = real(ifft(FT));             %back to time plane: Inverse Transform
+   STD = 0;
+  
+   for i = 1:numoforient   
+      [mx, I] = max(IT(:,i));%maximum fourier filtered response
+      FMP(i,k) = I; %save it
+      
+      fst = I-Qtr;
+      snd = I+Qtr;
+      if fst < 1, fst = 1; end
+      if snd > numofsamp, snd = numofsamp; end 
+      
+      temp = [ERP(1:fst,i); ERP(snd:end,i)];     
+      STD = STD + std(temp);      %and standard deviation
+     % MN(i) = mean(temp);         %and mean of spontaneous baseline
+
+      ERPsm(:,i) = ERPsm(:,i) - mean(temp);   %for plotting substract baseline
+   end
+   STD = STD /numoforient;
+   MX = max(max(ERPsm));
+%    
+%    figure(3), plot(ERPsm), hold on
+%    line([1 numofsamp], [STD STD])
+%    title(['Channel: ' num2str(k)])
+%    pause;
+%    hold off
+   
+   if MX > 2*STD%7*STD
+       CHAN(k) = 1;      %this channel is OK
+       RA = MX/STD*0.2;
+  %     figure(2)
+       for i = 1:numoforient
+          Ind = find(ERPsm(:,i) > (1.5 + RA)*STD);   %find all values greater than the mean + 1.5*the standard error
+          R = round(length(Ind)/2);                            %within original responses
+          shift = R;
+          I1 = FMP(i,k) - R + shift;
+          I2 = FMP(i,k) + R + shift;
+          if I2 > numofsamp, I2 = numofsamp; end          
+          while IT(I1, i) > IT(I2, i) && shift > -R && I1 > 1
+                shift = shift -1;
+                I1 = FMP(i,k) - R + shift;
+                I2 = FMP(i,k) + R + shift;
+                if I2 > numofsamp, I2 = numofsamp; end 
+          end
+          FSZ(i,k).onset = -R + shift;        %Take as onset
+          FSZ(i,k).offset = - (R + shift);    %Take as offset
+          
+
+%           plot(ERPsm(:,i)), hold on, h = axis; 
+%           line([FMP(i,k) + FSZ(i,k).onset FMP(i,k)+ FSZ(i,k).onset ],[h(3) h(4)]) %onset response
+%           line([FMP(i,k) FMP(i,k)] , [h(3) h(4)])                       %midpoint response
+%           line([FMP(i,k) - FSZ(i,k).offset FMP(i,k) - FSZ(i,k).offset],[h(3) h(4)])  %offset response
+%           line(xlim,7*STD*[1 1])
+%           title(['Channel: ' num2str(k) '   Orient=' num2str(i)])
+%           pause
+%            hold off  
+           
+          FMP(i,k) = FMP(i,k) + shift;        %Take as middelpoint
+       end
+       %get average onset from onset and opposite offset response
+        for i = 1:2:numoforient 
+             FSZ(i,k).onset = round((FSZ(i,k).onset + FSZ((mod((i+3),8)+1),k).offset)/2);
+        end
+        
+        WH(k).w2 = (FSZ(3,k).onset + FSZ(7,k).onset)/2*DegperS/sampf; %half width
+        WH(k).h2 = (FSZ(1,k).onset + FSZ(5,k).onset)/2*DegperS/sampf; %half height
+        
+       for i = 1:numoforient
+           CP(i,k) = FMP(i,k) + round((FSZ(i,k).onset - FSZ((mod((i+3),8)+1),k).onset)/2);
+       end
+       
+   else
+%        disp(['Reject channel: '  num2str(k)] )
+       
+   end
+%     figure, polar(RAD,FSZ(:,6)/sampf.*DegperS)
+%     title(['Channel: ' num2str(k)]) 
+%     pause
+end
+
+CHAN = logical(CHAN);
+Ic = find(CHAN);
+WH = WH(CHAN);
+%ChNm = length(Ic);
+CP = (CP(:,CHAN)./sampf - MP).*DegperS;
+FMP = (FMP(:,CHAN)./sampf - MP).*DegperS;
+
+
+% Onset = zeros(numoforient, ChNm);
+% O = FSZ(:,CHAN);
+% for i = 1:ChNm
+%     Onset(:,i) = [O(:,i).onset]';
+% end
+% Onset = Onset.*DegperS/sampf;
+% Onset(9,:) = Onset(1,:);
+% Onset = Onset(1:2:9,:); %take horizontal and vertical borders
+%//////////////alternative method to calculate receptive field centers
+%     x = 1:4;
+%     mp = (FMP(x,:) - FMP((mod((x+3),8)+1),:))/2;
+%     figure, plot(-mp(3,:)+SC.x, mp(1,:)+SC.y, '.')
+%//////////////////////////////////////////////////////////////
+    
+    
+posdat = fft(CP);
+%get amplitude and phase of the second spectral factor
+amplitude = abs(posdat(2,:))*2/numoforient;    
+phase = -angle(posdat(2,:)); %sin(x) = cos(x-.5*pi)
+phase = phase + .5*pi;      %because first motion direction is upwards; from +0.5pi
+if phase < 0
+    phase = 2*pi + phase;
+end
+
+[Mid.x Mid.y] = pol2cart(phase, amplitude);
+Mid.x = Mid.x + SC.x;
+Mid.y = Mid.y + SC.y;
+
+hotspot = fft(FMP);
+%get amplitude and phase of the second spectral factor
+amplitude = abs(hotspot(2,:))*2/numoforient;    
+phase = -angle(hotspot(2,:)); %sin(x) = cos(x-.5*pi)
+phase = phase + .5*pi;      %because first motion direction is upwards; from +0.5pi
+if phase < 0
+    phase = 2*pi + phase;
+end
+[Hot.x Hot.y] = pol2cart(phase, amplitude);
+Hot.x = Hot.x + SC.x;
+Hot.y = Hot.y + SC.y;
+
+
+
+
+
+% figure
+% H1 = polar(phase, amplitude, '.k');
+% hold on
+% 
+% set(H1,'markersize', 20);
+% XDATA1 = get(H1, 'xdata');
+% YDATA1 = get(H1, 'ydata');
+% for i = 1:length(XDATA)
+%      TH = text(XDATA(i), YDATA(i), num2str(Ic(i)) );
+%      set(TH, 'Color', [.5 .5 .5])
+%      set(TH, 'FontSize', 16)
+%  end
+% 
+% XDATA1 = XDATA1 + SC.x;
+% YDATA1 = YDATA1 + SC.y;
+% 
+% hotspot = fft(FMP);
+% %get amplitude and phase of the second spectral factor
+% amplitude = abs(hotspot(2,:))*2/numoforient;    
+% phase = -angle(hotspot(2,:)); %sin(x) = cos(x-.5*pi)
+% phase = phase + .5*pi;      %because first motion direction is upwards; from +0.5pi
+% if phase < 0
+%     phase = 2*pi + phase;
+% end
+%                                            
+% figure;
+% H2 = polar(phase, amplitude, '.k');
+
+% for i = 1:length(phase)
+%     polar(phase(i), amplitude(i));
+% end
+
+% set(H1,'markersize', 20);
+% XDATA = get(H1, 'xdata');
+% YDATA = get(H1, 'ydata');
+% for i = 1:length(XDATA)
+%      TH = text(XDATA(i), YDATA(i), num2str(Ic(i)) );
+%      set(TH, 'Color', [.5 .5 .5])
+%      set(TH, 'FontSize', 16)
+%  end
+% 
+% XDATA = XDATA + SC.x;
+% YDATA = YDATA + SC.y;
+
+% p = ((0:4).').*0.5*pi - .5*pi;
+% p = repmat(p,1,length(Ic)); 
+% RFX = Onset.*cos(p) + repmat(Mid.x, 5, 1); 
+% RFY = Onset.*sin(p) + repmat(Mid.y, 5, 1);
+
+clr = rand(length(Ic),3);
+circle.y = sin(0:0.2*pi:2*pi).*0.1;
+circle.x = cos(0:0.2*pi:2*pi).*0.1;
+
+% figure;
+% 
+% hold on
+% for chan = 1:length(Ic)
+% %    h = plot(RFX(:,chan), RFY(:,chan), 'color', clr(chan,:));
+%     M = [Mid.x(chan) Mid.y(chan)];
+%  %   w = WH(chan).w2; h = WH(chan).h2; Col =  clr(chan,:);
+%    box(WH(chan).w2, WH(chan).h2, M, clr(chan,:))
+%    plot(circle.x + Hot.x(chan), circle.y + Hot.y(chan), 'color', clr(chan,:));
+% 
+%    
+%    z = text(Mid.x(chan), Mid.y(chan), ['* ' num2str(Ic(chan))]);
+%    set(z,'color', clr(chan,:));
+% end
+  
+axis('on')
+% axis('equal')
+% grid on
+
+
+RF_INFO.Mid=Mid;
+RF_INFO.WH=WH;
+RF_INFO.clr=clr;
+RF_INFO.Ic=Ic;
+
+
+
+function box(w, h, M, Col)
+
+H(1)  = line([M(1) - w M(1) + w], [M(2) - h M(2) - h]);
+H(2)  = line([M(1) + w M(1) + w], [M(2) - h M(2) + h]);
+H(3)  = line([M(1) - w M(1) + w], [M(2) + h M(2) + h]);
+H(4)  = line([M(1) - w M(1) - w], [M(2) - h M(2) + h]);
+
+for i = 1:4
+    set(H(i), 'Color', Col);
+end
+

BIN
SCRIPTS/FUNCTIONS/SUPPORT/SelectFG.fig


+ 199 - 0
SCRIPTS/FUNCTIONS/SUPPORT/SelectFG.m

@@ -0,0 +1,199 @@
+function varargout = SelectFG(varargin)
+% SELECTFG MATLAB code for SelectFG.fig
+%      SELECTFG, by itself, creates a new SELECTFG or raises the existing
+%      singleton*.
+%
+%      H = SELECTFG returns the handle to a new SELECTFG or the handle to
+%      the existing singleton*.
+%
+%      SELECTFG('CALLBACK',hObject,eventData,handles,...) calls the local
+%      function named CALLBACK in SELECTFG.M with the given input arguments.
+%
+%      SELECTFG('Property','Value',...) creates a new SELECTFG or raises
+%      the existing singleton*.  Starting from the left, property value pairs are
+%      applied to the GUI before SelectFG_OpeningFcn gets called.  An
+%      unrecognized property name or invalid value makes property application
+%      stop.  All inputs are passed to SelectFG_OpeningFcn via varargin.
+%
+%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
+%      instance to run (singleton)".
+%
+% See also: GUIDE, GUIDATA, GUIHANDLES
+
+% Edit the above text to modify the response to help SelectFG
+
+% Last Modified by GUIDE v2.5 02-Feb-2017 16:55:38
+global select
+
+% Begin initialization code - DO NOT EDIT
+gui_Singleton = 1;
+gui_State = struct('gui_Name',       mfilename, ...
+                   'gui_Singleton',  gui_Singleton, ...
+                   'gui_OpeningFcn', @SelectFG_OpeningFcn, ...
+                   'gui_OutputFcn',  @SelectFG_OutputFcn, ...
+                   'gui_LayoutFcn',  [] , ...
+                   'gui_Callback',   []);
+if nargin && ischar(varargin{1})
+    gui_State.gui_Callback = str2func(varargin{1});
+end
+
+if nargout
+    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
+else
+    gui_mainfcn(gui_State, varargin{:});
+end
+% End initialization code - DO NOT EDIT
+
+% --- Executes just before SelectFG is made visible.
+function SelectFG_OpeningFcn(hObject, eventdata, handles, varargin)
+% This function has no output args, see OutputFcn.
+% hObject    handle to figure
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+% varargin   command line arguments to SelectFG (see VARARGIN)
+
+% Choose default command line output for SelectFG
+handles.output = hObject;
+
+% Update handles structure
+guidata(hObject, handles);
+
+
+% UIWAIT makes SelectFG wait for user response (see UIRESUME)
+% uiwait(handles.figure1);
+
+
+% --- Outputs from this function are returned to the command line.
+function varargout = SelectFG_OutputFcn(hObject, eventdata, handles)
+% varargout  cell array for returning output args (see VARARGOUT);
+% hObject    handle to figure
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+
+% Get default command line output from handles structure
+varargout{1} = handles.output;
+
+
+
+% --- Executes on selection change in FG.
+function FG_Callback(hObject, eventdata, handles)
+global select
+% hObject    handle to FG (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+contents = cellstr(get(hObject,'String'));
+select.fg = contents{get(hObject,'Value')};
+% Hints: contents = cellstr(get(hObject,'String')) returns FG contents as cell array
+%        contents{get(hObject,'Value')} returns selected item from FG
+
+
+% --- Executes during object creation, after setting all properties.
+function FG_CreateFcn(hObject, eventdata, handles)
+% hObject    handle to FG (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    empty - handles not created until after all CreateFcns called
+
+% Hint: listbox controls usually have a white background on Windows.
+%       See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+    set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes on selection change in MS.
+function MS_Callback(hObject, eventdata, handles)
+global select
+% hObject    handle to MS (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+contents = cellstr(get(hObject,'String'));
+select.ms = contents{get(hObject,'Value')};
+% Hints: contents = cellstr(get(hObject,'String')) returns MS contents as cell array
+%        contents{get(hObject,'Value')} returns selected item from MS
+
+
+% --- Executes during object creation, after setting all properties.
+function MS_CreateFcn(hObject, eventdata, handles)
+% hObject    handle to MS (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    empty - handles not created until after all CreateFcns called
+
+% Hint: listbox controls usually have a white background on Windows.
+%       See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+    set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes on selection change in Visual.
+function Visual_Callback(hObject, eventdata, handles)
+global select
+% hObject    handle to Visual (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+contents = cellstr(get(hObject,'String'));
+select.vis = contents{get(hObject,'Value')};
+% Hints: contents = cellstr(get(hObject,'String')) returns Visual contents as cell array
+%        contents{get(hObject,'Value')} returns selected item from Visual
+
+
+% --- Executes during object creation, after setting all properties.
+function Visual_CreateFcn(hObject, eventdata, handles)
+% hObject    handle to Visual (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    empty - handles not created until after all CreateFcns called
+
+% Hint: listbox controls usually have a white background on Windows.
+%       See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+    set(hObject,'BackgroundColor','white');
+end
+
+
+% --- Executes on selection change in Monkey.
+function Monkey_Callback(hObject, eventdata, handles)
+global select
+% hObject    handle to Monkey (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+contents = cellstr(get(hObject,'String'));
+select.monkey = contents{get(hObject,'Value')};
+% Hints: contents = cellstr(get(hObject,'String')) returns Monkey contents as cell array
+%        contents{get(hObject,'Value')} returns selected item from Monkey
+
+
+% --- Executes during object creation, after setting all properties.
+function Monkey_CreateFcn(hObject, eventdata, handles)
+% hObject    handle to Monkey (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    empty - handles not created until after all CreateFcns called
+
+% Hint: listbox controls usually have a white background on Windows.
+%       See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+    set(hObject,'BackgroundColor','white');
+end
+
+
+
+function SNR_Callback(hObject, eventdata, handles)
+% hObject    handle to SNR (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    structure with handles and user data (see GUIDATA)
+global select
+% Hints: get(hObject,'String') returns contents of SNR as text
+%        str2double(get(hObject,'String')) returns contents of SNR as a double
+select.SNR = str2double(get(hObject,'String'));
+
+% --- Executes during object creation, after setting all properties.
+function SNR_CreateFcn(hObject, eventdata, handles)
+global select
+% hObject    handle to SNR (see GCBO)
+% eventdata  reserved - to be defined in a future version of MATLAB
+% handles    empty - handles not created until after all CreateFcns called
+
+% Hint: edit controls usually have a white background on Windows.
+%       See ISPC and COMPUTER.
+if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
+    set(hObject,'BackgroundColor','white');
+end

+ 67 - 0
SCRIPTS/FUNCTIONS/SUPPORT/micsaccdeg.m

@@ -0,0 +1,67 @@
+% Function for detecting microsaccades from a time series of eye movements.
+%
+% Inputs:
+%    EyeDeg   - Time series of eye movements
+%    SAMPLING - The sampling rate of the time series of eye movements.
+%
+% Outputs:
+%    microsaccades - Column one: Time of onset of microsaccades
+%                    Column two: Time at which the microsaccdes terminate
+%                    Column three: Peak velocity of microsaccades
+%                    Column four: Peak amplitude of microsaccades
+%                    
+% Haider Riaz - haider.riaz@mail.mcgill.ca
+% McIntyre Medical Building Room 1225
+% Department of Physiology, McGill University
+%
+% Created by Haider Riaz Khan 2013.
+
+function microsaccades = micsaccdeg(EyeDeg, SAMPLING)
+
+N = length(EyeDeg); 
+v = zeros(N,3);
+for k=1:N
+    v(k,1)= EyeDeg(k,1);
+end
+
+for k=2:N-1  
+    if k>=3 & k<=N-2
+        v(k,2:3) = SAMPLING/6*[EyeDeg(k+2,2)+EyeDeg(k+1,2)-...
+            EyeDeg(k-1,2)-EyeDeg(k-2,2) EyeDeg(k+2,3)+EyeDeg(k+1,3)-...
+            EyeDeg(k-1,3)-EyeDeg(k-2,3)];
+    end
+end
+
+vel = sqrt(v(:,2).^2 + v(:,3).^2);
+
+i=1;
+onset = [];
+finish = [];
+vpeak = [];
+ampl = [];
+while(i<=N)
+    j=1;
+    
+    if vel(i) >=8
+        while(vel(i+j) >= 8)
+            j = j + 1;
+        end
+        j = j-1;
+        
+        if j>=5 && j<=150
+            onset = vertcat(onset,i);
+            finish = vertcat(finish , (j+i));
+            vpeak = vertcat(vpeak, max(vel(i: (j+i))));% peak velocity
+            ampl = vertcat(ampl,sqrt( (EyeDeg(i,2)-EyeDeg(i+j,2))^2 + ...
+                (EyeDeg(i,3)-EyeDeg(j+i,3))^2 ));  % amplitude
+            i = i + j + 10;
+        else
+            i = i + j + 1;
+        end
+    else
+        i = i + 1;
+    end  
+end
+microsaccades = [onset , finish , vpeak , ampl];
+
+end

+ 203 - 0
SCRIPTS/FUNCTIONS/SUPPORT/preProcessV1MS.m

@@ -0,0 +1,203 @@
+function V1MS = preProcessV1MS(V1MS,EffectWindow)
+
+    % This fucntion pre precess the structure V1MS before the figures are
+    % computed. Among other thigns, it rejects channels where the MS
+    % artefects are too big, merges the individual session channels into one
+    % channel when appropiate, computes effect size per unit, etc. 
+    
+    % Initialize parameters.
+    nMaxs = 10;
+    percentageToKeep = 0.75; % Percentage of channels with smaller artifact that we keep. 
+
+    excitatoryWindow = EffectWindow.exc;
+    supressionWindow = EffectWindow.sup;
+    
+    % In order to reject channels where (ater removal) the artifact is too
+    % big, we use the following proceedure. 1) For each soa, and each
+    % channel, we look at the average of the ten highes samples furing the
+    % MS window 2) We sort chanels based on that value. 3) We reject a
+    % certain percetange of the channels iwith highest averague value. 
+    
+    DIFFS = nan(length(V1MS.META.allSOAS),length(V1MS.iCH), 19);
+    for soa = 1:size(V1MS.ALLSOAS,2)
+        for ch = 1:size(V1MS.ALLCHS,1)
+            iTIME       = V1MS.TIME > (V1MS.ALLSOAS(ch,soa)) & ...
+                V1MS.TIME < (V1MS.ALLSOAS(ch,soa)+0.025);
+            iTIMEplot   = V1MS.TIME > (V1MS.ALLSOAS(ch,soa)-0.015) & ...
+                V1MS.TIME < (V1MS.ALLSOAS(ch,soa)+0.025+0.015);
+
+            iSOAS = find(V1MS.ALLSOAS(ch,soa) == V1MS.META.allSOAS);
+            DIFFS(iSOAS,ch,:) = squeeze(V1MS.ALLCHS(ch,iTIME,soa+1)-...
+                V1MS.ALLCHS(ch,iTIME,1));
+        end
+    end
+
+    DIFF = squeeze(nanmean(DIFFS,1));
+    MEANS = nan(1,size(DIFF,1));
+    
+    for ch = 1:size(DIFF,1)
+        temp = sort(squeeze(DIFF(ch,:)));
+        MEANS(ch) = nanmean(temp(end-(nMaxs-1):end));
+    end
+
+    temp = sort(MEANS);temp = temp(~isnan(temp));ind = ...
+        round(percentageToKeep*length(temp));
+    THRS = temp(ind);
+    indS = MEANS < THRS;
+
+    V1MS.LIST.SOAS = [];
+    V1MS.LIST.CHNS = [];
+    V1MS.LIST.indS = repmat(indS',3,1);
+
+    for soa = 1:3
+        V1MS.LIST.SOAS = [V1MS.LIST.SOAS; V1MS.ALLSOAS(:,soa)];
+        V1MS.LIST.CHNS = cat(1,V1MS.LIST.CHNS, ...
+            squeeze(V1MS.ALLCHS(:,:,soa+1)));
+    end
+
+    % Remove Channels below the threshold
+    for chu = 1:size(V1MS.CHUNKS,2)    
+        sign = V1MS.CHUNKS(chu).DATA;
+        cova = V1MS.CHUNKS(chu).COVA;
+        for bl = 1:size(sign,1)        
+            for ch = 1:size(sign,3)            
+                diffs = nan(3,19);
+                for soa = 1:length(V1MS.CHUNKS(1).INFO.MStimes)   
+                    iTIME       = V1MS.TIME > (V1MS.CHUNKS(1).INFO.MStimes(soa)/1000) & ...
+                        V1MS.TIME < (V1MS.CHUNKS(1).INFO.MStimes(soa)/1000+0.025); 
+                    diffs(soa,:) = squeeze(sign(bl,iTIME,ch,soa+1)-sign(bl,iTIME,ch,1));                
+                end
+                diff = sort(squeeze(nanmean(diffs,1)));
+                MAX = nanmean(diff(end-(nMaxs-1):end));            
+                if MAX > THRS                
+                    sign(bl,:,ch,:) = nan;
+                    cova(bl,:,ch,:) = nan;
+                end            
+            end        
+        end
+        V1MS.CHUNKS(chu).DATA = sign;
+        V1MS.CHUNKS(chu).COVA = cova;
+    end
+
+    % Now procced to average for every chunk. Then take every electrode as a unit. 
+    for chu = 1:size(V1MS.CHUNKS,2)    
+        sign = V1MS.CHUNKS(chu).DATA;
+        cova = V1MS.CHUNKS(chu).COVA;
+        V1MS.CHUNKS(chu).AVE =  squeeze(nanmean(sign,1));
+        V1MS.CHUNKS(chu).meanCOVA =  squeeze(nanmean(cova,1));
+    end
+
+    % Make a copy and check whther each electrode should or suoldn't be included.
+    for chu = 1:size(V1MS.CHUNKS,2)
+
+        V1MS.CHUNKS(chu).CLEAN.AVE = V1MS.CHUNKS(chu).AVE;
+        V1MS.CHUNKS(chu).CLEAN.meanCOVA = V1MS.CHUNKS(chu).meanCOVA;
+        V1MS.CHUNKS(chu).CLEAN.IND = nan(size(V1MS.CHUNKS(chu).MESBL,1),1);
+
+        for ch = 1:size(V1MS.CHUNKS(chu).MESBL,1)
+            tempSIGNIF = zeros(3,1);
+            for soa = 1:3
+                tempSIGNIF(soa) = ttest2(squeeze(V1MS.CHUNKS(chu).MESBL(ch,soa,:)),...
+                    squeeze(V1MS.CHUNKS(chu).MESMS(ch,soa,:)));
+            end
+
+            if ~isnan(sum(tempSIGNIF)) && sum(tempSIGNIF)~= 0
+                V1MS.CHUNKS(chu).CLEAN.IND(ch) = 1;
+            elseif isnan(sum(tempSIGNIF))
+                V1MS.CHUNKS(chu).CLEAN.IND(ch) = nan;
+            else
+                V1MS.CHUNKS(chu).CLEAN.IND(ch) = 0;
+                V1MS.CHUNKS(chu).CLEAN.AVE(:,ch,:) = nan;
+                V1MS.CHUNKS(chu).CLEAN.meanCOVA(:,ch,:) = nan;
+            end
+        end
+
+    end
+
+    % Concatenate all elctrodes together
+    V1MS.UNITS = [];
+    V1MS.CLEAN.UNITS = [];
+    V1MS.CLEAN.COVA = [];
+    V1MS.CLEAN.UNITSIND = [];
+    V1MS.MONKEY         = [];
+    V1MS.RFDATA         = [];
+    V1MS.PERF           = [];
+    V1MS.PERF_MONKEY = [];
+    for chu = 1:size(V1MS.CHUNKS,2)
+        V1MS.UNITS          = cat(2,V1MS.UNITS,V1MS.CHUNKS(chu).AVE);
+        V1MS.CLEAN.UNITS    = cat(2,V1MS.CLEAN.UNITS,V1MS.CHUNKS(chu).CLEAN.AVE);
+        V1MS.CLEAN.COVA    = cat(2,V1MS.CLEAN.COVA,V1MS.CHUNKS(chu).CLEAN.meanCOVA);
+        V1MS.CLEAN.UNITSIND = [V1MS.CLEAN.UNITSIND; V1MS.CHUNKS(chu).CLEAN.IND];
+        V1MS.MONKEY         = cat(2,V1MS.MONKEY,V1MS.CHUNKS(chu).INFO.MONKEY);
+        V1MS.RFDATA         =  cat(1,V1MS.RFDATA,V1MS.CHUNKS(chu).INFO.RFDATA);
+        if nansum(V1MS.CHUNKS(chu).CLEAN.IND)
+            V1MS.PERF         =  cat(1,V1MS.PERF,V1MS.CHUNKS(chu).PERF); 
+            V1MS.PERF_MONKEY  =  [V1MS.PERF_MONKEY ...
+                ones(1,size(V1MS.CHUNKS(chu).PERF,1))*...
+                (strcmp(V1MS.CHUNKS(chu).INFO.MONKEY{1},'C')+1)];
+        end
+    end
+    V1MS.CLEAN.UNITSIND(isnan(V1MS.CLEAN.UNITSIND)) = 0;
+
+    % compute average accross channels
+    V1MS.AVE = squeeze(nanmean(V1MS.UNITS,2));
+
+    % compute average accross channels with an effect
+    V1MS.CLEAN.AVE = squeeze(nanmean(V1MS.CLEAN.UNITS,2));
+    V1MS.CLEAN.meanCOVA = squeeze(nanmean(V1MS.CLEAN.COVA,2));
+
+    % Effect for all channels
+    EFFECT = nan(3,size(V1MS.UNITS,2));
+    V1MS.META.S = 10; BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.UNITS,2)        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+ excitatoryWindow(1)) & ...
+                V1MS.TIME < (V1MS.META.allSOAS(soa)+excitatoryWindow(2));        
+            EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.UNITS(iT,ch,soa+1) - ...
+                V1MS.UNITS(iT,ch,1)));     
+        end   
+    end
+    V1MS.EFFECT = EFFECT;
+
+    % Effect for significative channels
+    EFFECT = nan(3,size(V1MS.CLEAN.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.CLEAN.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+excitatoryWindow(1)) & ...
+                V1MS.TIME < (V1MS.META.allSOAS(soa)+excitatoryWindow(2));        
+            EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.CLEAN.UNITS(iT,ch,soa+1) - ...
+                V1MS.CLEAN.UNITS(iT,ch,1)));        
+        end 
+    end
+    V1MS.CLEAN.EFFECT = EFFECT;
+    
+    % Suppresive Effect for all channels
+    SUPPR_EFFECT = nan(3,size(V1MS.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+supressionWindow(1)) & ...
+                V1MS.TIME < (V1MS.META.allSOAS(soa)+supressionWindow(2));        
+            SUPPR_EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.UNITS(iT,ch,soa+1) - ...
+                V1MS.UNITS(iT,ch,1)));      
+        end   
+    end
+    V1MS.SUPPR_EFFECT = SUPPR_EFFECT;
+
+    % Suppresive Effect for significative channels
+    SUPPR_EFFECT = nan(3,size(V1MS.CLEAN.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.CLEAN.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+supressionWindow(1)) & ...
+                V1MS.TIME < (V1MS.META.allSOAS(soa)+supressionWindow(2));        
+            SUPPR_EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.CLEAN.UNITS(iT,ch,soa+1) - ...
+                V1MS.CLEAN.UNITS(iT,ch,1)));%/nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));        
+        end 
+    end
+    V1MS.CLEAN.SUPPR_EFFECT = SUPPR_EFFECT;
+end

+ 211 - 0
SCRIPTS/FUNCTIONS/SUPPORT/preProcessV1MS_S7.m

@@ -0,0 +1,211 @@
+function V1MS = preProcessV1MS_CK(V1MS,EffectWindow,cv1i)
+
+    % This fucntion pre precess the structure V1MS before the figures are
+    % computed. Among other thigns, it rejects channels where the MS
+    % artefects are too big, merges the individual session channels into one
+    % channel when appropiate, computes effect size per unit, etc. 
+    
+    % Initialize parameters.
+    nMaxs = 10;
+    percentageToKeep = 0.75; % Percentage of channels with smaller artifact that we keep. 
+    
+%     excitatoryWindow = [0 0.05];
+%     supressionWindow = [0.25 2;];
+
+    excitatoryWindow = EffectWindow.exc;
+    supressionWindow = EffectWindow.sup;
+    
+    % In order to reject channels where (ater removal) the artifact is too
+    % big, we use the following proceedure. 1) For each soa, and each
+    % channel, we look at the average of the ten highes samples furing the
+    % MS window 2) We sort chanels based on that value. 3) We reject a
+    % certain percetange of the channels iwith highest averague value. 
+    
+    DIFFS = nan(length(V1MS.META.allSOAS),length(V1MS.iCH), 19);
+    for soa = 1:size(V1MS.ALLSOAS,2)
+        for ch = 1:size(V1MS.ALLCHS,1)
+            iTIME       = V1MS.TIME > (V1MS.ALLSOAS(ch,soa)) & V1MS.TIME < (V1MS.ALLSOAS(ch,soa)+0.025);
+            iTIMEplot   = V1MS.TIME > (V1MS.ALLSOAS(ch,soa)-0.015) & V1MS.TIME < (V1MS.ALLSOAS(ch,soa)+0.025+0.015);
+
+
+            iSOAS = find(V1MS.ALLSOAS(ch,soa) == V1MS.META.allSOAS);
+            DIFFS(iSOAS,ch,:) = squeeze(V1MS.ALLCHS(ch,iTIME,soa+1)-V1MS.ALLCHS(ch,iTIME,1));
+        end
+    end
+
+    DIFF = squeeze(nanmean(DIFFS,1));
+    MEANS = nan(1,size(DIFF,1));
+    
+    for ch = 1:size(DIFF,1)
+        temp = sort(squeeze(DIFF(ch,:)));
+        MEANS(ch) = nanmean(temp(end-(nMaxs-1):end));
+    end
+
+    temp = sort(MEANS);temp = temp(~isnan(temp));ind = round(percentageToKeep*length(temp));
+    THRS = temp(ind);
+    indS = MEANS < THRS;
+
+
+
+    V1MS.LIST.SOAS = [];
+    V1MS.LIST.CHNS = [];
+    V1MS.LIST.indS = repmat(indS',3,1);
+
+    for soa = 1:3
+
+        V1MS.LIST.SOAS = [V1MS.LIST.SOAS; V1MS.ALLSOAS(:,soa)];
+        V1MS.LIST.CHNS = cat(1,V1MS.LIST.CHNS, squeeze(V1MS.ALLCHS(:,:,soa+1)));
+
+    end
+
+    % Remove Channels below the threshold
+
+    for chu = 1:size(V1MS.CHUNKS,2)    
+        sign = V1MS.CHUNKS(chu).DATA;
+        cova = V1MS.CHUNKS(chu).COVA;
+        for bl = 1:size(sign,1)        
+            for ch = 1:size(sign,3)            
+                diffs = nan(3,19);
+                for soa = 1:length(V1MS.CHUNKS(1).INFO.MStimes)   
+                    iTIME       = V1MS.TIME > (V1MS.CHUNKS(1).INFO.MStimes(soa)/1000) & V1MS.TIME < (V1MS.CHUNKS(1).INFO.MStimes(soa)/1000+0.025); 
+                    diffs(soa,:) = squeeze(sign(bl,iTIME,ch,soa+1)-sign(bl,iTIME,ch,1));                
+                end
+                diff = sort(squeeze(nanmean(diffs,1)));
+                MAX = nanmean(diff(end-(nMaxs-1):end));            
+                if MAX > THRS                
+                    sign(bl,:,ch,:) = nan;
+                    cova(bl,:,ch,:) = nan;
+                end            
+            end        
+        end
+        V1MS.CHUNKS(chu).DATA = sign;
+        V1MS.CHUNKS(chu).COVA = cova;
+    end
+
+    % Now procced to average for every chunk. Then take every electrode as a unit. 
+
+    for chu = 1:size(V1MS.CHUNKS,2)    
+        sign = V1MS.CHUNKS(chu).DATA;
+        cova = V1MS.CHUNKS(chu).COVA;
+        V1MS.CHUNKS(chu).AVE =  squeeze(nanmean(sign,1));
+        V1MS.CHUNKS(chu).meanCOVA =  squeeze(nanmean(cova,1));
+    end
+
+    % Make a copy and check whther each electrode should or suoldn't be included.
+
+    for chu = 1:size(V1MS.CHUNKS,2)
+
+        V1MS.CHUNKS(chu).CLEAN.AVE = V1MS.CHUNKS(chu).AVE;
+        V1MS.CHUNKS(chu).CLEAN.meanCOVA = V1MS.CHUNKS(chu).meanCOVA;
+        V1MS.CHUNKS(chu).CLEAN.IND = nan(size(V1MS.CHUNKS(chu).MESBL,1),1);
+
+        for ch = 1:size(V1MS.CHUNKS(chu).MESBL,1)
+            tempSIGNIF = zeros(3,1);
+            for soa = 1:3
+                tempSIGNIF(soa) = ttest2(squeeze(V1MS.CHUNKS(chu).MESBL(ch,soa,:)),squeeze(V1MS.CHUNKS(chu).MESMS(ch,soa,:)));
+            end
+
+            if ~isnan(sum(tempSIGNIF)) && sum(tempSIGNIF)~= 0
+                V1MS.CHUNKS(chu).CLEAN.IND(ch) = 1;
+            elseif isnan(sum(tempSIGNIF))
+                V1MS.CHUNKS(chu).CLEAN.IND(ch) = nan;
+            else
+                V1MS.CHUNKS(chu).CLEAN.IND(ch) = 0;
+                V1MS.CHUNKS(chu).CLEAN.AVE(:,ch,:) = nan;
+                V1MS.CHUNKS(chu).CLEAN.meanCOVA(:,ch,:) = nan;
+            end
+        end
+
+    end
+
+    % Concatenate all elctrodes together
+
+    V1MS.UNITS = [];
+    V1MS.CLEAN.UNITS = [];
+    V1MS.CLEAN.COVA = [];
+    V1MS.CLEAN.UNITSIND = [];
+    V1MS.MONKEY         = [];
+    V1MS.RFDATA         = [];
+    V1MS.PERF           = [];
+    V1MS.PERF_MONKEY = [];
+    for chu = 1:size(V1MS.CHUNKS,2)
+
+        V1MS.UNITS          = cat(2,V1MS.UNITS,V1MS.CHUNKS(chu).AVE);
+        V1MS.CLEAN.UNITS    = cat(2,V1MS.CLEAN.UNITS,V1MS.CHUNKS(chu).CLEAN.AVE);
+        V1MS.CLEAN.COVA    = cat(2,V1MS.CLEAN.COVA,V1MS.CHUNKS(chu).CLEAN.meanCOVA);
+        V1MS.CLEAN.UNITSIND = [V1MS.CLEAN.UNITSIND; V1MS.CHUNKS(chu).CLEAN.IND];
+        V1MS.MONKEY         = cat(2,V1MS.MONKEY,V1MS.CHUNKS(chu).INFO.MONKEY);
+        V1MS.RFDATA         =  cat(1,V1MS.RFDATA,V1MS.CHUNKS(chu).INFO.RFDATA);
+        if nansum(V1MS.CHUNKS(chu).CLEAN.IND)
+            V1MS.PERF         =  cat(1,V1MS.PERF,V1MS.CHUNKS(chu).PERF); 
+            V1MS.PERF_MONKEY  =  [V1MS.PERF_MONKEY ones(1,size(V1MS.CHUNKS(chu).PERF,1))*(strcmp(V1MS.CHUNKS(chu).INFO.MONKEY{1},'C')+1)];
+        end
+    end
+    
+    V1MS.CLEAN.UNITSIND(isnan(V1MS.CLEAN.UNITSIND)) = 0;
+
+    % compute average accross channels
+
+    V1MS.AVE = squeeze(nanmean(V1MS.UNITS(:,logical(cv1i),:),2));
+
+    % compute average accross channels with an effect
+
+    V1MS.CLEAN.AVE = squeeze(nanmean(V1MS.CLEAN.UNITS(:,logical(cv1i),:),2));
+    V1MS.CLEAN.meanCOVA = squeeze(nanmean(V1MS.CLEAN.COVA,2));
+
+    % Effect for all channels
+
+    EFFECT = nan(3,size(V1MS.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+ excitatoryWindow(1)) & V1MS.TIME < (V1MS.META.allSOAS(soa)+excitatoryWindow(2));        
+            EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.UNITS(iT,ch,soa+1) - V1MS.UNITS(iT,ch,1)));%/nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));      
+        end   
+    end
+
+    V1MS.EFFECT = EFFECT;
+
+    % Effect for significative channels
+    EFFECT = nan(3,size(V1MS.CLEAN.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.CLEAN.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+excitatoryWindow(1)) & V1MS.TIME < (V1MS.META.allSOAS(soa)+excitatoryWindow(2));        
+            EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.CLEAN.UNITS(iT,ch,soa+1) - V1MS.CLEAN.UNITS(iT,ch,1)));%/nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));        
+        end 
+    end
+
+    V1MS.CLEAN.EFFECT = EFFECT;
+    
+    
+    % Suppresive Effect for all channels
+
+    SUPPR_EFFECT = nan(3,size(V1MS.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+supressionWindow(1)) & V1MS.TIME < (V1MS.META.allSOAS(soa)+supressionWindow(2));        
+            SUPPR_EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.UNITS(iT,ch,soa+1) - V1MS.UNITS(iT,ch,1)));%/nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));      
+        end   
+    end
+
+    V1MS.SUPPR_EFFECT = SUPPR_EFFECT;
+
+    % Suppresive Effect for significative channels
+    SUPPR_EFFECT = nan(3,size(V1MS.CLEAN.UNITS,2));
+    V1MS.META.S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V1MS.CLEAN.UNITS,2);        
+            iT = V1MS.TIME > (V1MS.META.allSOAS(soa)+supressionWindow(1)) & V1MS.TIME < (V1MS.META.allSOAS(soa)+supressionWindow(2));        
+            SUPPR_EFFECT(soa,ch) = nanmean(1*squeeze(V1MS.CLEAN.UNITS(iT,ch,soa+1) - V1MS.CLEAN.UNITS(iT,ch,1)));%/nanmax(smooth(V1MS.CLEAN.AVE(:,1),10));        
+        end 
+    end
+
+    V1MS.CLEAN.SUPPR_EFFECT = SUPPR_EFFECT;
+
+end

+ 197 - 0
SCRIPTS/FUNCTIONS/SUPPORT/preProcessV4MS.m

@@ -0,0 +1,197 @@
+function V4MS = preProcessV4MS(V4MS,EffectWindow)
+
+
+%     excitatoryWindow = [0 0.05];
+%     supressionWindow = [0.25 2];
+
+    excitatoryWindow = EffectWindow.exc;
+    supressionWindow = EffectWindow.sup;
+
+
+    nMaxs = 10;
+    THRS = [];
+
+    DIFFS = nan(3,length(V4MS.iCH), 19);
+    for soa = 1:length(V4MS.META.SOAS)
+
+        iTIME       = V4MS.TIME > (V4MS.META.SOAS(soa)) & V4MS.TIME < (V4MS.META.SOAS(soa)+0.025); 
+        iTIMEplot   = V4MS.TIME > (V4MS.META.SOAS(soa)-0.01) & V4MS.TIME < (V4MS.META.SOAS(soa)+0.025+0.01); 
+        plotDIFF    = squeeze(V4MS.ALLCHS(:,iTIMEplot,soa+1)-V4MS.ALLCHS(:,iTIMEplot,1));
+        DIFFS(soa,:,:) = squeeze(V4MS.ALLCHS(:,iTIME,soa+1)-V4MS.ALLCHS(:,iTIME,1));
+    end
+    %%
+
+    DIFF = squeeze(nanmean(DIFFS,1));
+    MEANS = nan(1,size(DIFF,1));
+
+    for ch = 1:size(DIFF,1)
+        temp = sort(squeeze(DIFF(ch,:)));
+        MEANS(ch) = nanmean(temp(end-(nMaxs-1):end));
+    end
+
+    temp = sort(MEANS);temp = temp(~isnan(temp));ind = round(0.75*length(temp));
+    THRS = temp(ind);
+    indS = MEANS < THRS;
+    %%
+    % Remove Channels below the threshold
+
+    for chu = 1:size(V4MS.CHUNKS,2)    
+        sign = V4MS.CHUNKS(chu).DATA;    
+        for bl = 1:size(sign,1)        
+            for ch = 1:size(sign,3)            
+                diffs = nan(3,19);
+                for soa = 1:length(V4MS.META.SOAS)   
+                    iTIME       = V4MS.TIME > (V4MS.META.SOAS(soa)) & V4MS.TIME < (V4MS.META.SOAS(soa)+0.025); 
+                    diffs(soa,:) = squeeze(sign(bl,iTIME,ch,soa+1)-sign(bl,iTIME,ch,1));
+                end
+    %             keyboard
+                diff = sort(squeeze(nanmean(diffs,1))); %CHANGED 2015-07-06, before diff = sort(squeeze(nanmean(diffs,1)));
+                MAX = nanmean(diff(end-(nMaxs-1):end));
+
+                if MAX > THRS
+                    sign(bl,:,ch,:) = nan;
+                end            
+            end        
+        end
+        V4MS.CHUNKS(chu).DATA = sign;
+    end
+    %%
+    % Now procced to average for every chunk. Then take every electrode as a unit. 
+
+    for chu = 1:size(V4MS.CHUNKS,2)    
+        sign = V4MS.CHUNKS(chu).DATA;
+        V4MS.CHUNKS(chu).AVE =  squeeze(nanmean(sign,1));
+    end
+
+    % Make a copy and check whther each electrode should or suoldn't be included.
+
+
+    for chu = 1:size(V4MS.CHUNKS,2)
+
+        V4MS.CHUNKS(chu).CLEAN.AVE = V4MS.CHUNKS(chu).AVE;
+        V4MS.CHUNKS(chu).CLEAN.IND = nan(size(V4MS.CHUNKS(chu).MESBL,1),1);
+
+        for ch = 1:size(V4MS.CHUNKS(chu).MESBL,1)
+            tempSIGNIF = zeros(3,1);
+            for soa = 1:3
+                tempSIGNIF(soa) = ttest2(squeeze(V4MS.CHUNKS(chu).MESBL(ch,soa,:)),squeeze(V4MS.CHUNKS(chu).MESMS(ch,soa,:)));
+            end
+
+            if ~isnan(sum(tempSIGNIF)) && sum(tempSIGNIF)~= 0 && ~isnan(nanmean(nanmean(V4MS.CHUNKS(chu).AVE(:,ch,:))))
+                V4MS.CHUNKS(chu).CLEAN.IND(ch) = 1;
+            elseif isnan(sum(tempSIGNIF)) || isnan(nanmean(nanmean(V4MS.CHUNKS(chu).AVE(:,ch,:))))
+                V4MS.CHUNKS(chu).CLEAN.IND(ch) = nan;
+            else
+                V4MS.CHUNKS(chu).CLEAN.IND(ch) = 0;
+                V4MS.CHUNKS(chu).CLEAN.AVE(:,ch,:) = nan;
+            end
+        end
+
+    end
+
+    % Concatenate all elctrodes together
+
+    V4MS.UNITS = [];
+    V4MS.CLEAN.UNITS = [];
+    V4MS.CLEAN.UNITSIND = [];
+    V4MS.MONKEY         = [];
+    V4MS.RFDATA         = [];
+    V4MS.PERF           = [];
+    V4MS.PERF_MONKEY = [];
+
+    for chu = 1:size(V4MS.CHUNKS,2)
+
+        V4MS.UNITS          = cat(2,V4MS.UNITS,V4MS.CHUNKS(chu).AVE);
+        V4MS.CLEAN.UNITS    = cat(2,V4MS.CLEAN.UNITS,V4MS.CHUNKS(chu).CLEAN.AVE);
+        V4MS.CLEAN.UNITSIND = [V4MS.CLEAN.UNITSIND; V4MS.CHUNKS(chu).CLEAN.IND];
+        V4MS.MONKEY         = cat(2,V4MS.MONKEY,V4MS.CHUNKS(chu).INFO.MONKEY);
+        V4MS.RFDATA         =  cat(1,V4MS.RFDATA,V4MS.CHUNKS(chu).INFO.RFDATA);
+        if nansum(V4MS.CHUNKS(chu).CLEAN.IND)
+            V4MS.PERF         =  cat(1,V4MS.PERF,V4MS.CHUNKS(chu).PERF); 
+            V4MS.PERF_MONKEY=   [V4MS.PERF_MONKEY ones(1,size(V4MS.CHUNKS(chu).PERF,1))*(strcmp(V4MS.CHUNKS(chu).INFO.MONKEY{1},'C')+1)];
+        end
+    end
+
+    for m = 1:length(V4MS.MONKEY)
+        if isempty(V4MS.MONKEY{m})
+            V4MS.MONKEY{m} = 'B';
+        end
+    end
+
+    V4MS.CLEAN.UNITSIND(isnan(V4MS.CLEAN.UNITSIND)) = 0;
+
+    %%
+    % compute average accross channels
+
+    V4MS.AVE = squeeze(nanmean(V4MS.UNITS,2));
+
+    V4MS.AVE_NON_SIG = squeeze(nanmean(V4MS.UNITS(:,~V4MS.CLEAN.UNITSIND,:),2));
+
+    % compute average accross channels with an effect
+
+    V4MS.CLEAN.AVE = squeeze(nanmean(V4MS.CLEAN.UNITS,2));
+
+    % Effect for all channels
+
+    EFFECT = nan(3,size(V4MS.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.UNITS,2);
+
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+supressionWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+supressionWindow(2));        
+            EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.UNITS(iT,ch,soa+1) - V4MS.UNITS(iT,ch,1)));
+
+        end
+
+    end
+
+    V4MS.EFFECT = EFFECT;
+
+    % Effect for significative channels
+
+    EFFECT = nan(3,size(V4MS.CLEAN.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.CLEAN.UNITS,2);        
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+supressionWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+supressionWindow(2));       
+            EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.CLEAN.UNITS(iT,ch,soa+1) - V4MS.CLEAN.UNITS(iT,ch,1)));        
+        end
+    end
+
+    V4MS.CLEAN.EFFECT = EFFECT;
+    
+    
+    % Excitatory Effect for all channels
+
+    EXCIT_EFFECT = nan(3,size(V4MS.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.UNITS,2);
+
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+excitatoryWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+excitatoryWindow(2));        
+            EXCIT_EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.UNITS(iT,ch,soa+1) - V4MS.UNITS(iT,ch,1)));
+
+        end
+
+    end
+
+    V4MS.EXCIT_EFFECT = EXCIT_EFFECT;
+
+    % Effect for significative channels
+
+    EXCIT_EFFECT = nan(3,size(V4MS.CLEAN.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.CLEAN.UNITS,2);        
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+excitatoryWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+excitatoryWindow(2));       
+            EXCIT_EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.CLEAN.UNITS(iT,ch,soa+1) - V4MS.CLEAN.UNITS(iT,ch,1)));        
+        end
+    end
+
+    V4MS.CLEAN.EXCIT_EFFECT = EXCIT_EFFECT;
+
+end

+ 189 - 0
SCRIPTS/FUNCTIONS/SUPPORT/preProcessV4MS_S7.m

@@ -0,0 +1,189 @@
+function V4MS = preProcessV4MS_CK(V4MS,EffectWindow,cv4i)
+
+%     excitatoryWindow = [0 0.05];
+%     supressionWindow = [0.25 2];
+    excitatoryWindow = EffectWindow.exc;
+    supressionWindow = EffectWindow.sup;
+
+    nMaxs = 10;
+    THRS = [];
+
+    DIFFS = nan(3,length(V4MS.iCH), 19);
+    for soa = 1:length(V4MS.META.SOAS)
+        iTIME       = V4MS.TIME > (V4MS.META.SOAS(soa)) & V4MS.TIME < (V4MS.META.SOAS(soa)+0.025); 
+        iTIMEplot   = V4MS.TIME > (V4MS.META.SOAS(soa)-0.01) & V4MS.TIME < (V4MS.META.SOAS(soa)+0.025+0.01); 
+        plotDIFF    = squeeze(V4MS.ALLCHS(:,iTIMEplot,soa+1)-V4MS.ALLCHS(:,iTIMEplot,1));
+        DIFFS(soa,:,:) = squeeze(V4MS.ALLCHS(:,iTIME,soa+1)-V4MS.ALLCHS(:,iTIME,1));
+    end
+    %%
+
+    DIFF = squeeze(nanmean(DIFFS,1));
+    MEANS = nan(1,size(DIFF,1));
+
+    for ch = 1:size(DIFF,1)
+        temp = sort(squeeze(DIFF(ch,:)));
+        MEANS(ch) = nanmean(temp(end-(nMaxs-1):end));
+    end
+
+    temp = sort(MEANS);temp = temp(~isnan(temp));ind = round(0.75*length(temp));
+    THRS = temp(ind);
+    indS = MEANS < THRS;
+    %%
+    % Remove Channels below the threshold
+
+    for chu = 1:size(V4MS.CHUNKS,2)    
+        sign = V4MS.CHUNKS(chu).DATA;    
+        for bl = 1:size(sign,1)        
+            for ch = 1:size(sign,3)            
+                diffs = nan(3,19);
+                for soa = 1:length(V4MS.META.SOAS)   
+                    iTIME       = V4MS.TIME > (V4MS.META.SOAS(soa)) & V4MS.TIME < (V4MS.META.SOAS(soa)+0.025); 
+                    diffs(soa,:) = squeeze(sign(bl,iTIME,ch,soa+1)-sign(bl,iTIME,ch,1));
+                end
+    %             keyboard
+                diff = sort(squeeze(nanmean(diffs,1))); %CHANGED 2015-07-06, before diff = sort(squeeze(nanmean(diffs,1)));
+                MAX = nanmean(diff(end-(nMaxs-1):end));
+
+                if MAX > THRS
+                    sign(bl,:,ch,:) = nan;
+                end            
+            end        
+        end
+        V4MS.CHUNKS(chu).DATA = sign;
+    end
+    %%
+    % Now proceed to average for every chunk. Then take every electrode as a unit. 
+    for chu = 1:size(V4MS.CHUNKS,2)    
+        sign = V4MS.CHUNKS(chu).DATA;
+        V4MS.CHUNKS(chu).AVE =  squeeze(nanmean(sign,1));
+    end
+
+    % Make a copy and check whether each electrode should or shouldn't be included.
+    for chu = 1:size(V4MS.CHUNKS,2)
+        V4MS.CHUNKS(chu).CLEAN.AVE = V4MS.CHUNKS(chu).AVE;
+        V4MS.CHUNKS(chu).CLEAN.IND = nan(size(V4MS.CHUNKS(chu).MESBL,1),1);
+        for ch = 1:size(V4MS.CHUNKS(chu).MESBL,1)
+            tempSIGNIF = zeros(3,1);
+            for soa = 1:3
+                tempSIGNIF(soa) = ttest2(squeeze(V4MS.CHUNKS(chu).MESBL(ch,soa,:)),squeeze(V4MS.CHUNKS(chu).MESMS(ch,soa,:)));
+            end
+
+            if ~isnan(sum(tempSIGNIF)) && sum(tempSIGNIF)~= 0 && ~isnan(nanmean(nanmean(V4MS.CHUNKS(chu).AVE(:,ch,:))))
+                V4MS.CHUNKS(chu).CLEAN.IND(ch) = 1;
+            elseif isnan(sum(tempSIGNIF)) || isnan(nanmean(nanmean(V4MS.CHUNKS(chu).AVE(:,ch,:))))
+                V4MS.CHUNKS(chu).CLEAN.IND(ch) = nan;
+            else
+                V4MS.CHUNKS(chu).CLEAN.IND(ch) = 0;
+                V4MS.CHUNKS(chu).CLEAN.AVE(:,ch,:) = nan;
+            end
+        end
+
+    end
+
+    % Concatenate all elctrodes together
+
+    V4MS.UNITS = [];
+    V4MS.CLEAN.UNITS = [];
+    V4MS.CLEAN.UNITSIND = [];
+    V4MS.MONKEY         = [];
+    V4MS.RFDATA         = [];
+    V4MS.PERF           = [];
+    V4MS.PERF_MONKEY = [];
+
+    for chu = 1:size(V4MS.CHUNKS,2)
+
+        V4MS.UNITS          = cat(2,V4MS.UNITS,V4MS.CHUNKS(chu).AVE);
+        V4MS.CLEAN.UNITS    = cat(2,V4MS.CLEAN.UNITS,V4MS.CHUNKS(chu).CLEAN.AVE);
+        V4MS.CLEAN.UNITSIND = [V4MS.CLEAN.UNITSIND; V4MS.CHUNKS(chu).CLEAN.IND];
+        V4MS.MONKEY         = cat(2,V4MS.MONKEY,V4MS.CHUNKS(chu).INFO.MONKEY);
+        V4MS.RFDATA         =  cat(1,V4MS.RFDATA,V4MS.CHUNKS(chu).INFO.RFDATA);
+        if nansum(V4MS.CHUNKS(chu).CLEAN.IND)
+            V4MS.PERF         =  cat(1,V4MS.PERF,V4MS.CHUNKS(chu).PERF); 
+            V4MS.PERF_MONKEY=   [V4MS.PERF_MONKEY ones(1,size(V4MS.CHUNKS(chu).PERF,1))*(strcmp(V4MS.CHUNKS(chu).INFO.MONKEY{1},'C')+1)];
+        end
+    end
+
+    for m = 1:length(V4MS.MONKEY)
+        if isempty(V4MS.MONKEY{m})
+            V4MS.MONKEY{m} = 'B';
+        end
+    end
+
+    V4MS.CLEAN.UNITSIND(isnan(V4MS.CLEAN.UNITSIND)) = 0;
+
+    %%
+    % compute average accross channels
+
+    V4MS.AVE = squeeze(nanmean(V4MS.UNITS(:,logical(cv4i),:),2));
+
+    V4MS.AVE_NON_SIG = squeeze(nanmean(V4MS.UNITS(...
+        :,~V4MS.CLEAN.UNITSIND,:),2));
+
+    % compute average accross channels with an effect
+
+    V4MS.CLEAN.AVE = squeeze(nanmean(V4MS.CLEAN.UNITS(:,logical(cv4i),:),2));
+
+    % Effect for all channels
+
+    EFFECT = nan(3,size(V4MS.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.UNITS,2);
+
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+supressionWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+supressionWindow(2));        
+            EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.UNITS(iT,ch,soa+1) - V4MS.UNITS(iT,ch,1)));
+
+        end
+
+    end
+
+    V4MS.EFFECT = EFFECT;
+
+    % Effect for significative channels
+
+    EFFECT = nan(3,size(V4MS.CLEAN.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.CLEAN.UNITS,2);        
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+supressionWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+supressionWindow(2));       
+            EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.CLEAN.UNITS(iT,ch,soa+1) - V4MS.CLEAN.UNITS(iT,ch,1)));        
+        end
+    end
+
+    V4MS.CLEAN.EFFECT = EFFECT;
+    
+    
+    % Excitatory Effect for all channels
+
+    EXCIT_EFFECT = nan(3,size(V4MS.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.UNITS,2);
+
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+excitatoryWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+excitatoryWindow(2));        
+            EXCIT_EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.UNITS(iT,ch,soa+1) - V4MS.UNITS(iT,ch,1)));
+
+        end
+
+    end
+
+    V4MS.EXCIT_EFFECT = EXCIT_EFFECT;
+
+    % Effect for significative channels
+
+    EXCIT_EFFECT = nan(3,size(V4MS.CLEAN.UNITS,2));
+    S = 10;
+    BINS = 40;
+    for soa = 1:3
+        for ch = 1:size(V4MS.CLEAN.UNITS,2);        
+            iT = V4MS.TIME > (V4MS.META.SOAS(soa)+excitatoryWindow(1)) & V4MS.TIME < (V4MS.META.SOAS(soa)+excitatoryWindow(2));       
+            EXCIT_EFFECT(soa,ch) = nanmean(1*squeeze(V4MS.CLEAN.UNITS(iT,ch,soa+1) - V4MS.CLEAN.UNITS(iT,ch,1)));        
+        end
+    end
+
+    V4MS.CLEAN.EXCIT_EFFECT = EXCIT_EFFECT;
+
+end

+ 14 - 0
SCRIPTS/FUNCTIONS/SUPPORT/print_figure.m

@@ -0,0 +1,14 @@
+function print_figure(NAME,POS,DIR,PRINT)
+    if PRINT
+        set(gcf,'PaperUnits','centimeters')
+        pre_pos = get(gcf,'PaperPosition');
+        set(gcf,'PaperPosition',POS)
+        [~,~] = mkdir(DIR);
+        cd(DIR)
+        print('-depsc','-r300',NAME)
+        print('-dtiff','-r300',NAME)
+        saveas(gcf,NAME)
+        set(gcf,'PaperPosition',pre_pos)
+    end
+end
+

+ 7 - 0
SCRIPTS/FUNCTIONS/SUPPORT/regressionTTest.m

@@ -0,0 +1,7 @@
+function [r,n,p,t] = regressionTTest(y,stats)
+
+n = sum(~isnan(y)) - 2;
+r = sqrt(stats(1));
+p = stats(3);
+
+t = r * sqrt((n)/ (1 - r^2));

+ 521 - 0
SCRIPTS/FUNCTIONS/V1V1_spikes_ms1p.m

@@ -0,0 +1,521 @@
+%% Population analysis of the straightforward MS data SPIKES ============
+% no MS vs MS @ 150ms, visual stimulus: homogenous texture
+% ------------------------------------------------------------
+% Loads an overview table of data to potentially include, imports the 
+% bandpass filtered data and saves it together in a population data file. 
+% Once this has been done, it can also directly load this file and work 
+% with that.
+
+% single pulses
+
+presaved = true; % 
+set_spike_window = false; % allows to set the spike thresholding windows
+MeanAlreadySubtracted = true;
+
+%% load info ============================================================
+load(fullfile(fld.data,'V1V1.mat'));
+if ~set_spike_window 
+    load(fullfile(fld.data,'V1V1_spikes.mat'));
+end
+
+%% load data ============================================================
+fprintf('Loading data..');
+if ~presaved
+    curr_sel = 0;
+    for ff=1:length(V1V1.Day)
+        indstr = V1V1.indeces(ff);
+        sep = find(indstr{1}=='_'==1);
+        sel_files = ...
+            [str2double(indstr{1}(1:sep-1)) str2double(indstr{1}(sep+1:end))];
+        if curr_sel ~= sel_files(1) % only load files once
+            curr_sel=sel_files(1);
+            % Wav2 = CH1-16
+            % Wave = CH17-32
+            if MeanAlreadySubtracted
+                % << artefact removal in raw
+                cd(fullfile(fld.data,'BANDPASS','BP3','500to5000'));
+            else
+                % << first BP version (no artefact removal in raw)
+                cd(fullfile(fld.data,'BANDPASS','BP','500to5000'));
+            end
+            
+            CHMap = [1:16;17:32];
+            CHi = [ones(1,16) ones(1,16).*2 ; 1:16 1:16];
+            
+            for df=1:2
+                fprintf(['Loading ' filenames{sel_files(df)} '\n']);
+                load(filenames{sel_files(df)},'Data')
+                D(df)=Data; clear Data; %#ok<*SAGROW>
+                t_vis = D(df).Time+0.150;
+            end
+        end
+        % Resave selected channels
+        % use 'CHi'
+        sC = V1V1.rec_channel(ff);
+        V1_V1(ff).info = V1V1(ff,:);
+        V1_V1(ff).ms_trials = ...
+            D(CHi(1,sC)).Trials(:,5)==1 & D(CHi(1,sC)).Trials(:,7)==1;
+        V1_V1(ff).ms_i = (find(V1_V1(ff).ms_trials==1))';
+        V1_V1(ff).noms_trials = ...
+            D(CHi(1,sC)).Trials(:,5)==1 & D(CHi(1,sC)).Trials(:,7)==2;
+        V1_V1(ff).noms_i = (find(V1_V1(ff).noms_trials==1))';
+        V1_V1(ff).t_vis = t_vis;
+        V1_V1(ff).d = D(CHi(1,sC)).Signal(:,CHi(2,sC),:);
+    end
+    cd(fld.scripts);
+    V1_V1_info = V1V1;
+    if MeanAlreadySubtracted
+        save(fullfile(fld.data,'V1V1_Selected2_1p'),...
+            'V1_V1','V1_V1_info','-v7.3');
+    else
+        save(fullfile(fld.data,'V1V1_Selected_1p'),...
+            'V1_V1','V1_V1_info','-v7.3');
+    end
+else
+    if MeanAlreadySubtracted
+        load(fullfile(fld.data,'V1V1_Selected2_1p.mat'));
+    else
+        load(fullfile(fld.data,'V1V1_Selected_1p.mat'));
+    end
+end
+fprintf('DONE!\n');
+
+%% Set the spike thresholding window ====================================
+if set_spike_window
+    % select a channel
+    sC = input(['Which data? (max ' num2str(length(V1_V1)) '): ']);
+    msw = [0.148 0.152];
+    MSmask = V1_V1(sC).t_vis>msw(1) & V1_V1(sC).t_vis<msw(2);
+    
+    figure
+    subplot(2,1,1);hold on;
+    for i=V1_V1(sC).noms_i
+        plot(V1_V1(sC).t_vis,V1_V1(sC).d(:,:,i));
+    end
+    set(gca,'xlim',[-.05 0.3],'ylim',[-500 400])
+    title(['All No MS Trials DataNum ' num2str(sC) ])
+    subplot(2,1,2);hold on;
+    for i=V1_V1(sC).ms_i
+        V1_V1(sC).md(:,:,i)=V1_V1(sC).d(:,:,i);
+        V1_V1(sC).md(MSmask,:,i)=0;
+        plot(V1_V1(sC).t_vis,V1_V1(sC).md(:,:,i));
+    end
+    set(gca,'xlim',[-.05 0.3],'ylim',[-500 400])
+    title(['All MS Trials DataNum ' num2str(sC) ])
+    
+    % set spike threshold window
+    if isfield(V1_V1(sC),'TH') && ~isempty(V1_V1(sC).TH)
+        TH = V1_V1(sC).TH;
+    else
+        V1_V1(sC).TH=[];
+        while isempty(V1_V1(sC).TH)
+            TH = input('Set spike threshold window: ');
+            % plot the histograms
+            PosNeg = -1; % neg peak detection
+            spikes.ms=[];spikes.noms=[];
+            n=0;
+            for i=V1_V1(sC).noms_i(1:end)
+                n=n+1;
+                y = V1_V1(sC).d(:,:,i);
+                [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
+                    'MinPeakHeight',TH(1));
+                xp(yp>TH(2))=[];
+                yp(yp>TH(2))=[];
+                spikes.noms=[spikes.noms; xp' yp ones(size(yp))*n];
+            end
+            n=0;
+            for i=V1_V1(sC).ms_i(1:end)
+                n=n+1;
+                y = V1_V1(sC).md(:,:,i);
+                [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
+                    'MinPeakHeight',TH(1));
+                xp(yp>TH(2))=[];
+                yp(yp>TH(2))=[];
+                spikes.ms=[spikes.ms; xp' yp ones(size(yp))*n];
+            end
+            
+            BinSpecs=[-200 5 400]./1000;
+            [spikes.noms_n, spikes.noms_bin] = ...
+                hist(spikes.noms(:,1),BinSpecs(1):BinSpecs(2):BinSpecs(3));
+            spikes.noms_n=spikes.noms_n./length(V1_V1(sC).noms_i);
+            [spikes.ms_n, spikes.ms_bin] = hist(spikes.ms(:,1),...
+                BinSpecs(1):BinSpecs(2):BinSpecs(3));
+            spikes.ms_n=spikes.ms_n./length(V1_V1(sC).ms_i);
+            
+            figure;
+            % Histograms -------
+            subplot(2,3,4);hold on;
+            bar(spikes.noms_bin(2:end-1),spikes.noms_n(2:end-1),'FaceColor','k','Barwidth',1)
+            peak = max(spikes.noms_n(spikes.noms_bin>0 & spikes.noms_bin<0.150));
+            plot([msw(1) msw(1)],[0 1000],'b--');
+            plot([msw(2) msw(2)],[0 1000],'b--')
+            set(gca,'xlim',[-0.1 0.350],'ylim',[0 peak*1.1])
+            title('No MS');
+            
+            subplot(2,3,5);hold on;
+            bar(spikes.ms_bin(2:end-1),spikes.ms_n(2:end-1),'FaceColor','r','EdgeColor','r','Barwidth',1)
+            peak = max(spikes.ms_n(spikes.ms_bin>0 & spikes.ms_bin<0.150));
+            plot([msw(1) msw(1)],[0 1000],'b--');
+            plot([msw(2) msw(2)],[0 1000],'b--')
+            set(gca,'xlim',[-0.1 0.350],'ylim',[0 peak*1.1])
+            title('MS');
+            
+            % Raster plots ------
+            subplot(2,3,1);hold on;
+            for i=1:length(V1_V1(sC).noms_i)
+                s=spikes.noms(:,3)==i;
+                plot(spikes.noms(s,1),spikes.noms(s,3),'ko',...
+                    'MarkerSize',3,'MarkerFaceColor','k')
+            end
+            plot([msw(1) msw(1)],[0 1000],'b--');
+            plot([msw(2) msw(2)],[0 1000],'b--')
+            set(gca,'xlim',[-0.1 0.35],'ylim',[0 i]);
+            title('No MS');
+            
+            subplot(2,3,2);hold on
+            for i=1:length(V1_V1(sC).ms_i)
+                s=spikes.ms(:,3)==i;
+                plot(spikes.ms(s,1),spikes.ms(s,3),'ro',...
+                    'MarkerSize',3,'MarkerFaceColor','r')
+            end
+            plot([msw(1) msw(1)],[0 1000],'b--');
+            plot([msw(2) msw(2)],[0 1000],'b--')
+            set(gca,'xlim',[-0.1 0.35],'ylim',[0 i]);
+            title('MS');
+            
+            % 2 histograms overlaid -----
+            subplot(2,3,3);hold on;
+            bar(spikes.noms_bin(2:end-1),spikes.noms_n(2:end-1),...
+                'EdgeColor','k','LineWidth',2,'FaceColor',...
+                'none','Barwidth',1)
+            bar(spikes.ms_bin(2:end-1),spikes.ms_n(2:end-1),...
+                'EdgeColor','r','LineWidth',2,'FaceColor',...
+                'none','Barwidth',1)
+            plot([msw(1) msw(1)],[0 1000],'b--');
+            plot([msw(2) msw(2)],[0 1000],'b--')
+            legend({'No MS','MS'})
+            set(gca,'xlim',[-0.05 0.350],'ylim',[0 peak*1.1])
+            title('No Ms vs. MS');
+            
+            % Difference zoomed in ------
+            subplot(2,3,6);hold on;
+            bar(spikes.noms_bin(2:end-1),...
+                spikes.ms_n(2:end-1)-spikes.noms_n(2:end-1),...
+                'EdgeColor','k','FaceColor','k','Barwidth',1)
+            plot(spikes.noms_bin(2:end-1),...
+                smooth(spikes.ms_n(2:end-1)-spikes.noms_n(2:end-1),5),...
+                'r','LineWidth',1)
+            plot([msw(1) msw(1)],[0 1000],'b--');
+            plot([msw(2) msw(2)],[0 1000],'b--')
+            set(gca,'xlim',[0.100 0.350],'ylim',[-0.08 0.3])
+            title('Difference MS-NoMS');
+            
+            % ask to approve
+            keepTH = input('Keep this spike window? (y/n): ','s');
+            if strcmp(keepTH,'y') || strcmp(keepTH,'Y')
+                V1_V1(sC).TH = TH;
+                close all;
+            end
+        end
+    end
+else
+    V1V1.TH1 = [V1V1_info{2:end,13}]';
+    V1V1.TH2 = [V1V1_info{2:end,14}]';
+    for sC = 1:size(V1_V1,2)
+        V1_V1(sC).TH = [V1V1.TH1(sC) V1V1.TH2(sC)];
+    end
+end
+
+%% Average ==============================================================
+fprintf('Processing spikes\n');
+if ~presaved
+    TrialSel = [...
+        3 10 40 10 40;...
+        6 1 70 1 55;...
+        10 70 215 70 215 ];
+    warning off %#ok<*WNOFF>
+    msw = [0.148 0.152];
+    MaskStimArtefact = false;
+    MaskStimBinOnly =true; % extrapolates previous timepoint
+    
+    BinSpecs=[-200 5 400]./1000;
+    PosNeg = -1; % neg peak detection
+    psth_nms=[];psth_ms=[];
+    fprintf('Making PSTHs\n')
+    for sC = 1:length(V1_V1)
+        fprintf([num2str(sC) '\n']);
+        spk(sC).ms=[];spk(sC).noms=[];
+        
+        if ismember(sC,TrialSel(:,1))
+            r=find(TrialSel(:,1)==sC);
+            nm_ti = TrialSel(r,2:3);
+            m_ti = TrialSel(r,4:5);
+        else
+            nm_ti = [1 length(V1_V1(sC).noms_i)];
+            m_ti = [1 length(V1_V1(sC).ms_i)];
+        end
+        n=0;
+        
+        % subtract average artefact shape ------
+        MSTi = V1_V1(sC).ms_i(m_ti(1):m_ti(2));
+        av_msTrace = nanmean(V1_V1(sC).d(:,:,MSTi),3);
+        SubtractAverage=false;
+        % --------------------------------------
+        
+        for i=V1_V1(sC).noms_i(nm_ti(1):nm_ti(2))
+            n=n+1;
+            y = V1_V1(sC).d(:,:,i);
+            [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
+                'MinPeakHeight',V1_V1(sC).TH(1));
+            xp(yp>V1_V1(sC).TH(2))=[];
+            yp(yp>V1_V1(sC).TH(2))=[];
+            spk(sC).noms=[spk(sC).noms; xp' yp ones(size(yp))*n];
+        end
+        n=0;
+        for i=V1_V1(sC).ms_i(m_ti(1):m_ti(2))
+            n=n+1;
+            if SubtractAverage
+                y = V1_V1(sC).d(:,:,i)-av_msTrace;
+                if MaskStimArtefact
+                    MSmask = V1_V1(sC).t_vis>msw(1) & V1_V1(sC).t_vis<msw(2);
+                    y(MSmask,:,:) = 0;
+                end
+            else
+                y = V1_V1(sC).d(:,:,i); %use masked trace
+            end
+            [yp,xp] = findpeaks(double(PosNeg.*y),V1_V1(sC).t_vis,...
+                'MinPeakHeight',V1_V1(sC).TH(1));
+            xp(yp>V1_V1(sC).TH(2))=[];
+            yp(yp>V1_V1(sC).TH(2))=[];
+            % remove spikes during pulse window
+            yp(xp>msw(1) & xp<msw(2))=[];
+            xp(xp>msw(1) & xp<msw(2))=[];
+            spk(sC).ms=[spk(sC).ms; xp' yp ones(size(yp))*n];
+        end
+                   
+        % sliding window approach ----
+        SlidWin.width = 0.010;
+        SlidWin.step = 0.001;
+        SlidWin.Min = -0.200;
+        SlidWin.Max = 0.350;
+        
+        spk(sC).noms_n = []; spk(sC).noms_bin = [];
+        for tstep = (SlidWin.Min-(SlidWin.width/2)):...
+                SlidWin.step:(SlidWin.Max-(SlidWin.width/2))
+            t1 = tstep; t2 = tstep+SlidWin.width;
+            y=sum(spk(sC).noms(:,1) >= t1 & spk(sC).noms(:,1) <= t2)/...
+                ( (t2-t1)*max(spk(sC).noms(:,3)));
+            spk(sC).noms_bin=[spk(sC).noms_bin tstep];
+            spk(sC).noms_n=[spk(sC).noms_n; y];
+        end
+        spk(sC).ms_n = []; spk(sC).ms_bin = [];
+        for tstep = (SlidWin.Min-(SlidWin.width/2)):...
+                SlidWin.step:(SlidWin.Max-(SlidWin.width/2))
+            t1 = tstep; t2 = tstep+SlidWin.width;
+            if t1>msw(1) && t1<=msw(2); t1 = msw(2); end
+            if t2>=msw(1) && t2<msw(2); t2 = msw(1); end
+            if t1<msw(1) && t2>=msw(2); t2 = msw(1); end
+            if abs(t1-msw(1))<SlidWin.step 
+                % don't change y
+            else
+                y=sum(spk(sC).ms(:,1) >= t1 & spk(sC).ms(:,1) <= t2)/...
+                    ((t2-t1)*max(spk(sC).ms(:,3)));
+            end
+            spk(sC).ms_bin=[spk(sC).ms_bin tstep];
+            spk(sC).ms_n=[spk(sC).ms_n; y];
+        end 
+        psth_nms=[psth_nms;spk(sC).noms_n']; %#ok<*AGROW>
+        psth_ms=[psth_ms;spk(sC).ms_n'];
+    end
+    if MeanAlreadySubtracted
+        save(fullfile(fld.data,'V1V1_spikes'),...
+            'spk','psth_nms','psth_ms', 'V1V1');
+    else
+        save(fullfile(fld.data,'V1V1_spikes2'),...
+            'spk','psth_nms','psth_ms', 'V1V1');
+    end
+    fprintf('DONE!\n')
+else
+    msw = [0.148 0.152];
+    if MeanAlreadySubtracted
+        load(fullfile(fld.data,'V1V1_spikes.mat'));
+    else
+        load(fullfile(fld.data,'V1V1_spikes2.mat'));
+    end
+    fprintf('DONE!\n')
+end
+
+%% subtract baseline, peak normalize & plot =============================
+t=spk(1).ms_bin;
+for s=1:size(spk,2)
+    y1=spk(s).noms_n; y2=spk(s).ms_n; 
+    y1_bl= y1-nanmean([y1(t>-0.100 & t<0); y2(t>-0.100 & t<0)]);
+    y2_bl= y2-nanmean([y1(t>-0.100 & t<0); y2(t>-0.100 & t<0)]);
+    yp = max(y1_bl(t>0 & t<0.100));
+    y1n=y1_bl./yp; y2n=y2_bl./yp;
+    spk(s).noms_n2=y1n; 
+    spk(s).ms_n2=y2n; 
+end
+
+for s=1:size(spk,2)
+    psth_nms(s,:) = spk(s).noms_n2; % Normalized
+    %psth_nms(s,:) = spk(s).noms_n;
+    psth_ms(s,:) = spk(s).ms_n2; % Normalized
+    %psth_ms(s,:) = spk(s).ms_n;
+end
+
+%% plot the traces ======================================================
+% select a subset of combinations
+sel = V1V1.ManSel==1;
+msw = [0.148 0.152];
+% sel = V1V1.current>0; % all
+
+N=sum(sel);
+fprintf(['Number of stim-rec combinations in average: ' num2str(N) '\n']);
+
+figure;
+% Histograms -------
+subplot(2,2,1);hold on;
+BL_nms = mean2(psth_nms(sel,spk(1).noms_bin(2:end-1)<0 & ...
+    spk(1).noms_bin(2:end-1)>-0.100));
+mPSTH_nms = mean(psth_nms(sel,2:end-1),1);%-BL_nms;
+sePSTH_nms = std(psth_nms(sel,2:end-1),1)./sqrt(length(sel));%-BL_nms;
+bar(spk(1).noms_bin(2:end-1),mPSTH_nms,'FaceColor','k','Barwidth',1)
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+set(gca,'xlim',[-0.05 0.350],'ylim',[-0.1 1.1])
+title('No MS');
+text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
+
+subplot(2,2,3);hold on;
+BL_ms = mean2(psth_ms(sel,spk(1).ms_bin(2:end-1)<0 & ...
+    spk(1).ms_bin(2:end-1)>-0.100));
+mPSTH_ms = mean(psth_ms(sel,2:end-1),1);%-BL_ms;
+sePSTH_ms = std(psth_ms(sel,2:end-1),1)./sqrt(length(sel));%-BL_nms;
+bar(spk(1).ms_bin(2:end-1),mPSTH_ms,'FaceColor','r',...
+    'EdgeColor','r','Barwidth',1)
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+set(gca,'xlim',[-0.05 0.350],'ylim',[-0.1 1.1])
+title('MS');
+text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
+
+% 2 histograms overlaid -----
+subplot(2,2,2);hold on;
+plot(spk(1).noms_bin(2:end-1),mPSTH_nms,'Color','k','LineWidth',2)
+plot(spk(1).ms_bin(2:end-1),mPSTH_ms,'Color','r','LineWidth',2)
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+legend({'No MS','MS'})
+set(gca,'xlim',[-0.05 0.350],'ylim',[-0.1 1.1])
+title('No Ms vs. MS');
+text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
+
+% Difference zoomed in ------
+subplot(2,2,4);hold on;
+bar(spk(1).noms_bin(2:end-1),mPSTH_ms-mPSTH_nms,...
+    'EdgeColor','k','FaceColor','k','Barwidth',1)
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+set(gca,'xlim',[0.100 0.30],'ylim',[-0.20 0.3])
+title('Difference MS-NoMS');
+text(0.26,0.20,['N = ' num2str(N)],'fontsize',12);
+
+print_figure('Fig2D' ,[0 0 32 20],fullfile(fld.figs,'FIG_2'),save_figs);
+cd(fld.scripts);
+
+%% sem-plot =============================================================
+figure;
+smw = 7;
+subplot(1,3,1);hold on;
+plot(spk(1).noms_bin(2:end-1),smooth(mPSTH_nms,smw),'k','LineWidth',2)
+plot(spk(1).ms_bin(2:end-1),smooth(mPSTH_ms,smw),'r','LineWidth',2)
+plot([-100 100],[0 0],'k');
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+legend({'No MS','MS'})
+set(gca,'xlim',[-0.05 0.350],'ylim',[-.1 1.1])
+title('No Ms vs. MS');
+text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
+
+subplot(1,3,2);hold on;
+x=spk(1).noms_bin(2:end-1);
+y=[mPSTH_nms-sePSTH_nms; mPSTH_nms; mPSTH_nms+sePSTH_nms];
+px=[x,fliplr(x)];
+py=[y(1,:), fliplr(y(3,:))];
+patch(px,smooth(py,smw),1,'FaceColor','k','FaceAlpha',0.3,'EdgeColor','none');
+plot(x,smooth(y(2,:),smw),'k');
+
+x=spk(1).ms_bin(2:end-1);
+y=[mPSTH_ms-sePSTH_ms; mPSTH_ms; mPSTH_ms+sePSTH_ms];
+px=[x,fliplr(x)];
+py=[y(1,:), fliplr(y(3,:))];
+patch(px,smooth(py,smw),1,'FaceColor','r','FaceAlpha',0.3,'EdgeColor','none');
+plot(x,smooth(y(2,:),smw),'r');
+plot([-100 100],[0 0],'k')
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+set(gca,'xlim',[-0.05 0.350],'ylim',[-.1 1.1])
+title('No Ms vs. MS (SEM)');
+text(0.25,0.8,['N = ' num2str(N)],'fontsize',12);
+
+subplot(1,3,3);hold on;
+area(spk(1).noms_bin(2:end-1),smooth(mPSTH_ms-mPSTH_nms,smw), 'FaceColor','k')
+plot([msw(1) msw(1)],[-100 100],'b--');
+plot([msw(2) msw(2)],[-100 100],'b--')
+set(gca,'xlim',[-0.1 0.350],'ylim',[-0.2 0.3])
+title('Ms-NoMS');
+text(0.25,0.25,['N = ' num2str(N)],'fontsize',12);
+
+%% Statistics ===========================================================
+ModWin = [0.150 0.160; 0.160 0.250];
+t=spk(1).noms_bin(2:end-1);
+MS = psth_ms(sel,2:end-1);
+NMS = psth_nms(sel,2:end-1);
+ExcWin = t>=ModWin(1,1) & t<=ModWin(1,2);
+SupWin = t>=ModWin(2,1) & t<=ModWin(2,2);
+ExcEffect = [mean(NMS(:,ExcWin),2) mean(MS(:,ExcWin),2)];
+SupEffect = [mean(NMS(:,SupWin),2) mean(MS(:,SupWin),2)];
+
+% 2-tailed
+[H_exc_2t,p_exc_2t, ci_exc_2t, stats_exc_2t] = ...
+    ttest(ExcEffect(:,1),ExcEffect(:,2),'tail','both');
+[H_sup_2t,p_sup_2t, ci_sup_2t, stats_sup_2t] = ...
+    ttest(SupEffect(:,1),SupEffect(:,2),'tail','both');
+
+% 1-tailed >> test specifically excitation and suppression
+[H_exc_1t,p_exc_1t, ci_exc_1t, stats_exc_1t] = ...
+    ttest(ExcEffect(:,1),ExcEffect(:,2),'tail','left');
+[H_sup_1t,p_sup_1t, ci_sup_1t, stats_sup_1t] = ...
+    ttest(SupEffect(:,1),SupEffect(:,2),'tail','right');
+
+figure;
+subplot(1,2,1);hold on;
+for s=1:size(ExcEffect,1)
+    plot(1:2,ExcEffect(s,:),'o-','Markersize',6);
+end
+errorbar(1:2,mean(ExcEffect),std(ExcEffect)./sqrt(size(ExcEffect,1)),...
+    'ko-','MarkerSize',10,'MarkerFaceColor','k','LineWidth',2)
+set(gca,'xtick',1:2,'xticklabel',{'No MS','MS'},'xlim',[.5 2.5]);
+title(['Excitatory Effect of Microstim (' num2str( 1000*(ModWin(1,1)-0.150) ) '-' ...
+    num2str( 1000*(ModWin(1,2)-0.150)) ' ms)']);
+
+subplot(1,2,2);hold on;
+for s=1:size(SupEffect,1)
+    plot(1:2,SupEffect(s,:),'o-','Markersize',6);
+end
+errorbar(1:2,mean(SupEffect),std(SupEffect)./sqrt(size(SupEffect,1)),...
+    'ko-','MarkerSize',10,'MarkerFaceColor','k','LineWidth',2)
+set(gca,'xtick',1:2,'xticklabel',{'No MS','MS'},'xlim',[.5 2.5]);
+title(['Suppressive Effect of Microstim (' num2str( 1000*(ModWin(2,1)-0.150) ) '-' ...
+    num2str( 1000*(ModWin(2,2)-0.150)) ' ms)']);
+
+fprintf(['\nMicrostimulation induced excitation:\n' ...
+    't(' num2str(stats_exc_1t.df) ') = ' num2str(stats_exc_1t.tstat) ...
+    ', p = ' num2str(p_exc_1t) '\n']);
+fprintf(['Microstimulation induced suppression:\n'...
+    't(' num2str(stats_sup_1t.df) ') = ' num2str(stats_sup_1t.tstat) ...
+    ', p = ' num2str(p_sup_1t) '\n']);
+
+%% Example plot for FIGURE 2A-C =========================================
+Check_IndV1;

+ 92 - 0
SCRIPTS/main.m

@@ -0,0 +1,92 @@
+% This script gives an overview of all the analysis step necessary to
+% recreate the figures and stats of Klink et al. (2017) Neuron
+% http://dx.doi.org/10.1016/j.neuron.2017.05.033
+
+%% Add function folders -------------------------------------------------
+fld.scripts = pwd;
+addpath(genpath('FUNCTIONS'));
+
+cd ../
+fld.project = pwd;
+
+cd(fld.scripts);
+
+%% Specify more folder paths --------------------------------------------
+fld.data = fullfile(fld.project,'DATA');
+fld.figs = fullfile(fld.project,'FIGURES'); mkdir(fld.figs);
+
+%% Figures Feedforward --------------------------------------------------
+% this generates a number of figure panels related to feedforward effects
+close all; clc;
+
+% load
+load(fullfile(fld.data,'V1MS_CAC.mat'));
+save_figs = true;
+
+% generate figures 
+FF_FIGURES;
+
+% close figures
+close all;
+
+%% Figures Feedback -----------------------------------------------------
+% this generates a number of figure panels related to feedback effects
+close all; clc;
+
+% load
+load(fullfile(fld.data,'V4MS_CAC.mat'));
+save_figs = true;
+
+% generate figures 
+FB_FIGURES;
+
+% close figures
+close all;
+
+%% Figures Figure-Ground ------------------------------------------------
+% this generates a number of figure panels related to fig-gnd effects
+close all; clc;
+save_figs = true;
+
+% generate figures 
+FG_FIGURES; 
+% close figures
+close all hidden;
+
+% Suppl figure 6
+FG_spikes_ms5p; 
+% close figures
+close all hidden;
+
+%% Stratification analysis ----------------------------------------------
+% this generates a number of figure panels related to stratification
+close all; clc;
+save_figs = true;
+
+% generate figures 
+STRAT_FIGURES;
+
+% close figures
+close all hidden;
+
+%% V1V1 analysis --------------------------------------------------------
+% this generates a number of figure panels related to interareal V1-MS
+close all; clc;
+save_figs = true;
+
+% generate figures 
+V1V1_spikes_ms1p;
+
+% close figures
+close all hidden;
+
+%% Eye Movement analysis ------------------------------------------------
+% This compares microsaccade amplitude and frequency between MS and no-MS
+close all; clc;
+save_figs = true;
+
+% generate figures 
+SACCADE_Analysis;
+
+% close figures
+close all hidden;