neuralAnalysesDelayShiftAligned.m 84 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380
  1. addpath(genpath('../../../my-tools'));
  2. addpath(genpath('../../../external-tools'));
  3. clearvars -except subjsData poolstack* pooltw*;
  4. %close all; clc;
  5. reload=0; recomp_shLRalgn=1;
  6. recomputelm=1;
  7. Nlag=10; Nspan=200; %Nspan=200;
  8. Nshf=10;
  9. selflag=1; %LookL during offer1 is most common
  10. %selflag=4; %LookR during offer2 is most common
  11. %selflag=2; %LookR during offer1 is less common
  12. %selflag=3; %LookL during offer2 is less common
  13. %caseflag=1; % perform analysis saccade-aligned forcing stare after first shift
  14. %caseflag=2; % perform analysis saccade-aligned ignoring gaze after first shift (removes data if second shifts are detected)
  15. %caseflag=3; % perform analysis for unilateral staring only trials
  16. %caseflag=4; % same as caseflag=1 but forcing offerLL/LR
  17. %caseflag=5; % same as caseflag=2 but forcing offerLL/LR
  18. %caseflag=6; % same as caseflag=3 but forcing offerLL/LR
  19. for selflag=4%[1 4]
  20. for caseflag=2
  21. clearvars -except subjsData reload recomp_shLRalgn recomputelm Nlag Nspan Nshf selflag caseflag; close all; clc;
  22. stareflag=(caseflag==1 | caseflag==4); %forces stare after saccade
  23. casesstrs={'1_shift_NOoffLR','2_shift_NOstare_NOoffLR','3_NOshift_NOoffLR','4_shift','5_shift_NOstare','6_NOshift'};
  24. disp(['running selflag=' num2str(selflag) '; caseflag=' num2str(caseflag) '; (' casesstrs{caseflag} ')']);
  25. switch selflag
  26. case 1
  27. %most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off1L_del1LR_sacc/';
  28. most_recent_folder=['../../Figures/Temp/NoBaselineNorm/evLevR_off_del_focus_minus200ms_apr24/evLevR_off1L_del1LR_' casesstrs{caseflag} '/'];
  29. if ~exist(most_recent_folder,'dir'); mkdir(most_recent_folder); mkdir([most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms']); end
  30. %most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off1L_del1LR_NOshift_NOoff1L/';
  31. selectedTimes='((ntce_ds(3,1)-46):ntce_ds(3,2))';
  32. %selectedCases{1}='find((cciso1LL) & (ccepx(:,tt)<0))';
  33. %selectedCases{2}='find((cciso1LL) & (ccepx(:,tt)>0))';
  34. case 2
  35. %most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off1R_del1LR_sacc/';
  36. most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off1R_del1LR_sacc/';
  37. selectedTimes='(ntce_ds(3,1):ntce_ds(3,2))';
  38. %selectedCases{1}='find((~cciso1LL) & (ccepx(:,tt)<0))';
  39. %selectedCases{2}='find((~cciso1LL) & (ccepx(:,tt)>0))';
  40. case 3
  41. %most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off2L_del2LR_sacc/';
  42. most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off2L_del2LR_shift/';
  43. %selectedTimes='(ntce_ds(5,1):ntce_ds(5,2))';
  44. selectedTimes='(ntce_ds(5,1):ntce_ds(6,1)-2)'; % FULL DELAY2
  45. %selectedCases{1}='find((cciso2LL) & (ccepx(:,tt)<0))';
  46. %selectedCases{2}='find((cciso2LL) & (ccepx(:,tt)>0))';
  47. case 4
  48. %most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off2R_del2LR_sacc/';
  49. most_recent_folder=['../../Figures/Temp/NoBaselineNorm/evLevR_off_del_focus_minus200ms_apr24/evLevR_off2R_del2LR_' casesstrs{caseflag} '/'];
  50. if ~exist(most_recent_folder,'dir'); mkdir(most_recent_folder); mkdir([most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms']); end
  51. %most_recent_folder='../../Figures/Temp/NoBaselineNorm/evLevR_off2R_del2LR_NOshift_NOoff2R/';
  52. selectedTimes='((ntce_ds(5,1)-46):ntce_ds(5,2))';
  53. %selectedTimes='(ntce_ds(5,1):ntce_ds(6,1)-2)'; % FULL DELAY2
  54. %selectedCases{1}='find((~cciso2LL) & (ccepx(:,tt)<0))';
  55. %selectedCases{2}='find((~cciso2LL) & (ccepx(:,tt)>0))';
  56. end
  57. % for off1L del1L/R
  58. % for off1R del1L/R
  59. % for off2L del2L/R
  60. % for off2R del2L/R
  61. if reload
  62. % if ~exist('subjsData','var')
  63. % subjsData(1).sbdata=getSubjectData(1);
  64. % subjsData(2).sbdata=getSubjectData(2);
  65. % end
  66. if ~exist('poolstackvars','var')
  67. load latestpoolstackvars_14feb22.mat
  68. end
  69. if ~exist('pooltweyepos','var')
  70. load latestpooltweyepos_14feb22.mat
  71. end
  72. if ~exist('pooltwspksq','var')
  73. load latestpooltwspks_14feb22.mat
  74. end
  75. twLabels={'preoffer1','offer1','delay1','offer2','delay2','refixate','choice-go','ch-hold'};
  76. nccs=[ 51 59 24 29 18 32 9 26];
  77. ntrs=arrayfun(@(xx) size(poolstackvars(xx).offer1sd,1),1:8);
  78. Nccs=sum(nccs);
  79. Ntrs12=max(ntrs);
  80. Ntps12=arrayfun(@(tw) size(pooltweyepos(tw).posX,3), 1:8);
  81. Ntps12(1)=400;
  82. pooloffer1sd=[]; poolofferLev=[]; poolofferRev=[]; pooloffer1ev=[]; pooloffer2ev=[]; pooloffer1rw=[]; pooloffer2rw=[]; poolofferchR=[];
  83. for sn=1:8
  84. pooloffer1sd=cat(2, pooloffer1sd, repmat(cat(1,poolstackvars(sn).offer1sd,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  85. poolofferLev=cat(2, poolofferLev, repmat(cat(1,poolstackvars(sn).offerLev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  86. poolofferRev=cat(2, poolofferRev, repmat(cat(1,poolstackvars(sn).offerRev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  87. pooloffer1ev=cat(2, pooloffer1ev, repmat(cat(1,poolstackvars(sn).offer1ev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  88. pooloffer2ev=cat(2, pooloffer2ev, repmat(cat(1,poolstackvars(sn).offer2ev,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  89. pooloffer1rw=cat(2, pooloffer1rw, repmat(cat(1,poolstackvars(sn).offer1rw,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  90. pooloffer2rw=cat(2, pooloffer2rw, repmat(cat(1,poolstackvars(sn).offer2rw,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  91. poolofferchR=cat(2, poolofferchR, repmat(cat(1,poolstackvars(sn).chooseR,nan(Ntrs12-ntrs(sn),1)),[1 nccs(sn)]));
  92. end
  93. pooleposxmat=cat(3,pooltweyepos(1).posX,pooltweyepos(2).posX,pooltweyepos(3).posX,pooltweyepos(4).posX,...
  94. pooltweyepos(5).posX,pooltweyepos(6).posX,pooltweyepos(7).posX,pooltweyepos(8).posX);
  95. poolspksqmat=cat(3,pooltwspksq(1).spkseqs,pooltwspksq(2).spkseqs,pooltwspksq(3).spkseqs,pooltwspksq(4).spkseqs,...
  96. pooltwspksq(5).spkseqs,pooltwspksq(6).spkseqs,pooltwspksq(7).spkseqs,pooltwspksq(8).spkseqs);
  97. poolspksqmat=cat(3,nan(size(pooltwspksq(1).spkseqs)),nan(size(pooltwspksq(2).spkseqs)),pooltwspksq(3).spkseqs,...
  98. nan(size(pooltwspksq(4).spkseqs)),pooltwspksq(5).spkseqs,nan(size(pooltwspksq(6).spkseqs)),nan(size(pooltwspksq(7).spkseqs)),nan(size(pooltwspksq(8).spkseqs)));
  99. poolcovhist=cat(2,pooltwspksq(1).covhist,pooltwspksq(2).covhist,pooltwspksq(3).covhist,pooltwspksq(4).covhist,...
  100. pooltwspksq(5).covhist,pooltwspksq(6).covhist,pooltwspksq(7).covhist,pooltwspksq(8).covhist);
  101. %clearvars pooltwspksq pooltweyepos
  102. %fchg=find(poolcovhist>=.8); fchl=find(poolcovhist<.8);
  103. fchg=find(poolcovhist>=.999); fchl=find(poolcovhist<.999);
  104. ntcv=[fchg(diff([fchg sum(Ntps12)])>1)' fchl([diff(fchl) sum(Ntps12)]>1)'];
  105. ntce=[[1; 401; ntcv(1:end-1,2)] [400; ntcv(:,1)]];
  106. vtps=ones(1,sum(Ntps12)); for jj=1:7; vtps(ntcv(jj,1):ntcv(jj,2))=nan; end
  107. %if sparsity==1 it means 1spike/ms that is 1000 spikes/s
  108. %nanmean(vectorise((nansum(poolspksqmat,3))./(nansum(poolspksqmat>=0,3))))*1000
  109. %nanstd(vectorise((nansum(poolspksqmat,3))./(nansum(poolspksqmat>=0,3))))*1000
  110. %% smooth by movmean filtering, downsample to 20ms, 50Hz resolution
  111. Ntps_ds=ceil(sum(Ntps12)/Nlag);
  112. tmax_ds=nanmovmean(1:size(pooleposxmat,3),Nlag,Nlag);
  113. poolspksqmat_ds=nan(Ntrs12,Nccs,length(tmax_ds));
  114. pooleposxmat_ds=nan(Ntrs12,Nccs,length(tmax_ds));
  115. for cc=1:Nccs
  116. poolspksqmat_ds(:,cc,:)=nanmovmean(squeeze(poolspksqmat(:,cc,:))',Nlag,[0 Nspan])';
  117. pooleposxmat_ds(:,cc,:)=nanmovmean(squeeze(pooleposxmat(:,cc,:))',Nlag,Nlag)';
  118. end
  119. clearvars poolspksqmat pooleposxmat
  120. %%
  121. poolcovhist_ds=nanmovmean(poolcovhist,Nlag,Nlag);
  122. %fcgh_ds=find(poolcovhist_ds>=.8); fchl_ds=find(poolcovhist_ds<.8);
  123. fcgh_ds=find(poolcovhist_ds>=.999); fchl_ds=find(poolcovhist_ds<.999);
  124. ntcv_ds=[fcgh_ds(diff([fcgh_ds Ntps_ds])>1)' fchl_ds([diff(fchl_ds) Ntps_ds]>1)'];
  125. vtps_ds=ones(1,Ntps_ds); for jj=1:7; vtps_ds(ntcv_ds(jj,1):ntcv_ds(jj,2))=nan; end
  126. ntce_ds=[[1 ceil(400/Nlag)+1 find(vtps_ds(2:end)+isnan(vtps_ds(1:end-1))==2)+1]' [ceil(400/Nlag) find(vtps_ds(1:end-1)+isnan(vtps_ds(2:end))==2)]'];
  127. Nvtps_ds=sum(vtps_ds==1);
  128. % Apply movmean independently across time windows
  129. % checktps_ds=zeros(1,length(poolcovhist_ds));
  130. % for tw=1:8
  131. % tpvec=zeros(1,length(poolcovhist));
  132. % tpvec(ntce(tw,1):ntce(tw,2))=1;
  133. % tpvec_ds=zeros(1,length(poolcovhist_ds));
  134. % tpvec_ds(ntce_ds(tw,1):ntce_ds(tw,2))=1;
  135. % for cc=1:Nccs
  136. % nnspktemp=nanmovmean(squeeze(poolspksqmat(:,cc,tpvec==1))',Nlag,[0 Nspan])';
  137. % poolspksqmat_ds(:,cc,tpvec_ds==1)=nnspktemp(:,1:sum(tpvec_ds==1));
  138. % nnepxtemp=nanmovmean(squeeze(pooleposxmat(:,cc,tpvec==1))',Nlag,Nlag)';
  139. % pooleposxmat_ds(:,cc,tpvec_ds==1)=nnepxtemp(:,1:sum(tpvec_ds==1));
  140. % end
  141. % checktps_ds(tpvec_ds==1)=checktps_ds(tpvec_ds==1)+tw;
  142. % end
  143. vtmax_ds=rmnans(tmax_ds.*vtps_ds);%find(rmnans(vtps_ds));
  144. rtmax_ds=1:length(vtmax_ds);
  145. rtmes_ds=arrayfun(@(jj) length(ntce_ds(jj,1):ntce_ds(jj,2)), 1:8);
  146. % baseline normalization
  147. %poolspksqmat_ds_bln=poolspksqmat_ds-repmat(nanmean(poolspksqmat_ds(:,:,1:floor(400/Nlag)),3),[1 1 Ntps_ds]);
  148. %clearvars poolspksqmat_ds
  149. % baseline normalization
  150. %poolspksqmat_ds_bln=poolspksqmat_ds./repmat(nanmean(poolspksqmat_ds(:,:,1:floor(400/Nlag)),3)+eps,[1 1 Ntps_ds]);
  151. %poolspksqmat_ds_bln=poolspksqmat_ds-repmat(nanmean(nanmean(poolspksqmat_ds(:,:,1:floor(400/Nlag)),3),1),[Ntrs12 1 Ntps_ds]);
  152. % No baseline normalization
  153. poolspksqmat_ds_bln=poolspksqmat_ds;
  154. else
  155. load pool_all_light.mat
  156. end
  157. %%
  158. % fullfig();
  159. % subplot(1,2,1);
  160. % spy(vectorisen(~isnan(pooleposxmat_ds_bln(1,cumsum(nccs),:)),1:2));
  161. % subplot(1,2,2);
  162. % spy(vectorisen(~isnan(poolspksqmat_ds_bln(1,cumsum(nccs),:)),1:2));
  163. %
  164. % fulldel2time=ntce_ds(5,1):ntce_ds(6,1)-20-2;
  165. %
  166. % fullfig();
  167. % subplot(1,2,1);
  168. % spy(vectorisen(~isnan(pooleposxmat_ds_bln(1,cumsum(nccs),fulldel2time)),1:2));
  169. % subplot(1,2,2);
  170. % spy(vectorisen(~isnan(poolspksqmat_ds_bln(1,cumsum(nccs),fulldel2time)),1:2));
  171. %%
  172. off1time=ntce_ds(2,2)-(19:-1:0);
  173. del1time=ntce_ds(3,2)-(19:-1:0);
  174. off2time=ntce_ds(4,2)-(19:-1:0);
  175. del2time=ntce_ds(5,2)-(19:-1:0);
  176. %fulldel1time=(ntce_ds(3,1)):ntce_ds(3,2);
  177. fulldel1time=[(ntce_ds(3,1)-46):(ntce_ds(3,1)-7) ntce_ds(3,1):ntce_ds(3,2)];
  178. %fulldel2time=(ntce_ds(5,1)):ntce_ds(6,1)-20-2; %due to spikecount/subsampling setup
  179. fulldel2time=[(ntce_ds(5,1)-46):(ntce_ds(5,1)-7) ntce_ds(5,1):ntce_ds(6,1)-20-2];
  180. num1stshiftsL=zeros(248,1);
  181. num2ndshiftsR=zeros(248,1);
  182. num1stshiftsR=zeros(248,1);
  183. num2ndshiftsL=zeros(248,1);
  184. if recomp_shLRalgn
  185. if selflag<=2
  186. %%%%%%%%%%%%%%
  187. pooleposxmat_shRalgn=nan(size(pooleposxmat_ds_bln));
  188. pooleposxmat_shLalgn=nan(size(pooleposxmat_ds_bln));
  189. poolspksqmat_shRalgn=nan(size(poolspksqmat_ds_bln));
  190. poolspksqmat_shLalgn=nan(size(poolspksqmat_ds_bln));
  191. pooleposxmat_shRonly=nan(size(pooleposxmat_ds_bln));
  192. pooleposxmat_shLonly=nan(size(pooleposxmat_ds_bln));
  193. poolspksqmat_shRonly=nan(size(poolspksqmat_ds_bln));
  194. poolspksqmat_shLonly=nan(size(poolspksqmat_ds_bln));
  195. isdelSR=nan(size(poolspksqmat_ds_bln,1:2));
  196. isdelSL=nan(size(poolspksqmat_ds_bln,1:2));
  197. for cc=1:248
  198. % firstL offer1 - thenL delay2
  199. % Detect saccades
  200. ccepx=squeeze(pooleposxmat_ds_bln(:,cc,fulldel1time));
  201. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,fulldel1time));
  202. [nuR,~,~,ishiftsR]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,+1,1,stareflag);
  203. % delay2 shiftR trials have sum(xdriftsR,2)>0
  204. isdelSR(:,cc)=double(~isnan(ishiftsR));
  205. ind_delSR=find(~isnan(ishiftsR));
  206. % saccade R times
  207. %stR=arrayfun(@(xx) find(xdriftsR(xx,:)==1,1,'first'),isSR);
  208. stR=ishiftsR(ind_delSR);
  209. num1stshiftsR(cc)=sum(nuR>0);
  210. for jj=1:length(ind_delSR)
  211. shRbins=(ishiftsR(ind_delSR(jj)):length(fulldel1time));
  212. %removes post-shift returns
  213. [n2L,~,~,ishifts2L]=nanmonotonicdrifts_forward_simplified(ccepx(ind_delSR(jj),shRbins(41:end)),2,0,-1,+1,stareflag);
  214. if n2L>0
  215. shRbins((41+ishifts2L):end)=[];
  216. num2ndshiftsL(cc)=num2ndshiftsL(cc)+1;
  217. end
  218. pooleposxmat_shRalgn(ind_delSR(jj),cc,fulldel1time)=[ccepx(ind_delSR(jj),shRbins) nan(1,length(fulldel1time)-sum(shRbins<=length(fulldel1time)))];
  219. poolspksqmat_shRalgn(ind_delSR(jj),cc,fulldel1time)=[ccspk(ind_delSR(jj),shRbins) nan(1,length(fulldel1time)-sum(shRbins<=length(fulldel1time)))];
  220. pooleposxmat_shRonly(ind_delSR(jj),cc,fulldel1time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  221. poolspksqmat_shRonly(ind_delSR(jj),cc,fulldel1time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  222. end
  223. %figure(); plot(1:76,squeeze(pooleposxmat_shRalgn(:,1,fulldel1time)))
  224. %%
  225. [nuL,~,~,ishiftsL]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,-1,1,stareflag);
  226. % delay2 shiftL trials
  227. isdelSL(:,cc)=double(~isnan(ishiftsL));
  228. ind_delSL=find(~isnan(ishiftsL));
  229. % saccade L times
  230. %stL=arrayfun(@(xx) find(xdriftsL(xx,:)==1,1,'first'),isSL);
  231. stL=ishiftsL(ind_delSL);
  232. num1stshiftsL(cc)=sum(nuL>0);
  233. for jj=1:length(ind_delSL)
  234. shLbins=(ishiftsL(ind_delSL(jj)):length(fulldel1time));
  235. %removes post-shift returns
  236. [n2R,~,~,ishifts2R]=nanmonotonicdrifts_forward_simplified(ccepx(ind_delSL(jj),shLbins(41:end)),2,0,+1,+1,stareflag);
  237. if n2R>0
  238. shLbins((41+ishifts2R):end)=[];
  239. num2ndshiftsR(cc)=num2ndshiftsR(cc)+1;
  240. end
  241. pooleposxmat_shLalgn(ind_delSL(jj),cc,fulldel1time)=[ccepx(ind_delSL(jj),shLbins) nan(1,length(fulldel1time)-sum(shLbins<=length(fulldel1time)))];
  242. poolspksqmat_shLalgn(ind_delSL(jj),cc,fulldel1time)=[ccspk(ind_delSL(jj),shLbins) nan(1,length(fulldel1time)-sum(shLbins<=length(fulldel1time)))];
  243. pooleposxmat_shLonly(ind_delSL(jj),cc,fulldel1time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  244. poolspksqmat_shLonly(ind_delSL(jj),cc,fulldel1time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  245. end
  246. %figure(); plot(1:76,squeeze(pooleposxmat_shLalgn(:,1,fulldel1time)))
  247. end
  248. %save('pool_del1_shLRalgn.mat','pooleposxmat_shRalgn','poolspksqmat_shRalgn','pooleposxmat_shLalgn','poolspksqmat_shLalgn','-v7.3')
  249. elseif selflag>2
  250. %%%%%%%%%%%%%%%%%%%%%%%
  251. pooleposxmat_shRalgn=nan(size(pooleposxmat_ds_bln));
  252. pooleposxmat_shLalgn=nan(size(pooleposxmat_ds_bln));
  253. poolspksqmat_shRalgn=nan(size(poolspksqmat_ds_bln));
  254. poolspksqmat_shLalgn=nan(size(poolspksqmat_ds_bln));
  255. pooleposxmat_shRonly=nan(size(pooleposxmat_ds_bln));
  256. pooleposxmat_shLonly=nan(size(pooleposxmat_ds_bln));
  257. poolspksqmat_shRonly=nan(size(poolspksqmat_ds_bln));
  258. poolspksqmat_shLonly=nan(size(poolspksqmat_ds_bln));
  259. isdelSR=nan(size(poolspksqmat_ds_bln,1:2));
  260. isdelSL=nan(size(poolspksqmat_ds_bln,1:2));
  261. for cc=1:248
  262. % firstL offer1 - thenL delay2
  263. % Detect saccades
  264. ccepx=squeeze(pooleposxmat_ds_bln(:,cc,fulldel2time));
  265. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,fulldel2time));
  266. [nuR,~,~,ishiftsR]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,+1,1,stareflag);
  267. % delay2 shiftR trials have sum(xdriftsR,2)>0
  268. isdelSR(:,cc)=double(~isnan(ishiftsR));
  269. ind_delSR=find(~isnan(ishiftsR));
  270. % saccade R times
  271. %stR=arrayfun(@(xx) find(xdriftsR(xx,:)==1,1,'first'),isSR);
  272. stR=ishiftsR(ind_delSR);
  273. num1stshiftsR(cc)=sum(nuR>0);
  274. for jj=1:length(ind_delSR)
  275. shRbins=(ishiftsR(ind_delSR(jj)):length(fulldel2time));
  276. %removes post-shift returns
  277. [n2L,~,~,ishifts2L]=nanmonotonicdrifts_forward_simplified(ccepx(ind_delSR(jj),shRbins(41:end)),2,0,-1,+1,stareflag);
  278. if n2L>0
  279. shRbins((41+ishifts2L):end)=[];
  280. num2ndshiftsL(cc)=num2ndshiftsL(cc)+1;
  281. end
  282. pooleposxmat_shRalgn(ind_delSR(jj),cc,fulldel2time)=[ccepx(ind_delSR(jj),shRbins) nan(1,length(fulldel2time)-sum(shRbins<=length(fulldel2time)))];
  283. poolspksqmat_shRalgn(ind_delSR(jj),cc,fulldel2time)=[ccspk(ind_delSR(jj),shRbins) nan(1,length(fulldel2time)-sum(shRbins<=length(fulldel2time)))];
  284. pooleposxmat_shRonly(ind_delSR(jj),cc,fulldel2time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  285. poolspksqmat_shRonly(ind_delSR(jj),cc,fulldel2time(1)-1+shRbins)=ccepx(ind_delSR(jj),shRbins);
  286. end
  287. [nuL,~,~,ishiftsL]=nanmonotonicdrifts_forward_simplified(ccepx(:,40:end),2,0,-1,1,stareflag);
  288. % delay2 shiftL trials
  289. isdelSL(:,cc)=double(~isnan(ishiftsL));
  290. ind_delSL=find(~isnan(ishiftsL));
  291. % saccade L times
  292. %stL=arrayfun(@(xx) find(xdriftsL(xx,:)==1,1,'first'),isSL);
  293. stL=ishiftsL(ind_delSL);
  294. num1stshiftsL(cc)=sum(nuL>0);
  295. for jj=1:length(ind_delSL)
  296. shLbins=(ishiftsL(ind_delSL(jj)):length(fulldel2time));
  297. %removes post-shift returns
  298. [n2R,~,~,ishifts2R]=nanmonotonicdrifts_forward_simplified(ccepx(ind_delSL(jj),shLbins(41:end)),2,0,+1,+1,stareflag);
  299. if n2R>0
  300. shLbins((41+ishifts2R):end)=[];
  301. num2ndshiftsR(cc)=num2ndshiftsR(cc)+1;
  302. end
  303. pooleposxmat_shLalgn(ind_delSL(jj),cc,fulldel2time)=[ccepx(ind_delSL(jj),shLbins) nan(1,length(fulldel2time)-sum(shLbins<=length(fulldel2time)))];
  304. poolspksqmat_shLalgn(ind_delSL(jj),cc,fulldel2time)=[ccspk(ind_delSL(jj),shLbins) nan(1,length(fulldel2time)-sum(shLbins<=length(fulldel2time)))];
  305. pooleposxmat_shLonly(ind_delSL(jj),cc,fulldel2time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  306. poolspksqmat_shLonly(ind_delSL(jj),cc,fulldel2time(1)-1+shLbins)=ccepx(ind_delSL(jj),shLbins);
  307. end
  308. %disp(cc)
  309. end
  310. %save('pool_del2_shLRalgn.mat','pooleposxmat_shRalgn','poolspksqmat_shRalgn','pooleposxmat_shLalgn','poolspksqmat_shLalgn','-v7.3')
  311. end
  312. else
  313. if selflag<=2
  314. load pool_del1_shLRalgn.mat
  315. elseif selflag>2
  316. load pool_del2_shLRalgn.mat
  317. end
  318. end
  319. sum(num1stshiftsL)/sum(ntrs.*nccs)
  320. sum(num1stshiftsR)/sum(ntrs.*nccs)
  321. sum(num2ndshiftsR)/sum(num1stshiftsL)
  322. sum(num2ndshiftsL)/sum(num1stshiftsR)
  323. sum(num2ndshiftsR)/sum(ntrs.*nccs)
  324. sum(num2ndshiftsL)/sum(ntrs.*nccs)
  325. %%
  326. pooleposxmat_L=nan(Ntrs12,Nccs,Ntps_ds); pooleposxmat_R=nan(Ntrs12,Nccs,Ntps_ds);
  327. if any(caseflag==[1 2 4 5])
  328. pooleposxmat_L=pooleposxmat_shLalgn(:,:,:);
  329. pooleposxmat_R=pooleposxmat_shRalgn(:,:,:);
  330. else
  331. dtime=eval(selectedTimes);
  332. inddelstL=arrayfun(@(xx) all((rmnans(squeeze(pooleposxmat_ds_bln(xx,1,dtime))))<=0), 1:size(pooleposxmat_ds_bln,1));
  333. inddelstR=arrayfun(@(xx) all((rmnans(squeeze(pooleposxmat_ds_bln(xx,1,dtime))))>=0), 1:size(pooleposxmat_ds_bln,1));
  334. pooleposxmat_L(1:sum(inddelstL),:,dtime)=pooleposxmat_ds_bln(inddelstL,:,dtime);
  335. pooleposxmat_R(1:sum(inddelstR),:,dtime)=pooleposxmat_ds_bln(inddelstR,:,dtime);
  336. end
  337. if selflag <=2
  338. hfig=fullfig();
  339. subplot(1,2,1); title('Shifts to Left screen side');
  340. plot(rtmax_ds,(squeeze(pooleposxmat_L(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  341. xlabel('time after delay1 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  342. subplot(1,2,2); title('Shifts to Right screen side');
  343. plot(rtmax_ds,(squeeze(pooleposxmat_R(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  344. xlabel('time after delay1 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  345. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.png']);
  346. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.fig']);
  347. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.svg']);
  348. fullfig();
  349. subplot(1,2,1);
  350. plotmsem(fulldel1time,nanmedian(squeeze(pooleposxmat_L(:,1,fulldel1time))),'k');
  351. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),99), fulldel1time),'color',[1 1 1].*.85);
  352. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),01), fulldel1time),'color',[1 1 1].*.85);
  353. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),95), fulldel1time),'color',[1 1 1].*.60);
  354. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),05), fulldel1time),'color',[1 1 1].*.60);
  355. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),90), fulldel1time),'color',[1 1 1].*.45);
  356. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),10), fulldel1time),'color',[1 1 1].*.45);
  357. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),75), fulldel1time),'color',[1 1 1].*.25);
  358. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),25), fulldel1time),'color',[1 1 1].*.25);
  359. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),65), fulldel1time),'color',[0 0 1].*.1);
  360. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),35), fulldel1time),'color',[1 1 1].*.1); %ylim([-1 1]);
  361. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  362. subplot(1,2,2);
  363. plotmsem(fulldel1time,nanmedian(squeeze(pooleposxmat_R(:,1,fulldel1time))),'k');
  364. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),99), fulldel1time),'color',[1 1 1].*.85);
  365. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),01), fulldel1time),'color',[1 1 1].*.85);
  366. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),95), fulldel1time),'color',[1 1 1].*.60);
  367. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),05), fulldel1time),'color',[1 1 1].*.60);
  368. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),90), fulldel1time),'color',[1 1 1].*.45);
  369. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),10), fulldel1time),'color',[1 1 1].*.45);
  370. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),75), fulldel1time),'color',[1 1 1].*.25);
  371. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),25), fulldel1time),'color',[1 1 1].*.25);
  372. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),65), fulldel1time),'color',[0 0 1].*.1);
  373. plot(fulldel1time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),35), fulldel1time),'color',[1 1 1].*.1); %ylim([-1 1]);
  374. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  375. else
  376. hfig=fullfig();
  377. subplot(1,2,1); title('Shifts to Left screen side');
  378. plot(rtmax_ds,(squeeze(pooleposxmat_L(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  379. xlabel('time after delay2 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  380. subplot(1,2,2); title('Shifts to Right screen side');
  381. plot(rtmax_ds,(squeeze(pooleposxmat_R(:,1,vtps_ds==1)))./32558); ylim([-1 1]); plothline(0);
  382. xlabel('time after delay2 aligned to gaze shift initiation (ms)'); ylabel('horizontal eye position (normalized)'); box off
  383. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.png']);
  384. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.fig']);
  385. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sample_trials_off_del_shifts_monitor.svg']);
  386. %%
  387. fullfig();
  388. subplot(1,2,1);
  389. plotmsem(fulldel2time,nanmedian(squeeze(pooleposxmat_L(:,1,fulldel2time))),'k');
  390. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),99), fulldel2time),'color',[1 1 1].*.85);
  391. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),01), fulldel2time),'color',[1 1 1].*.85);
  392. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),95), fulldel2time),'color',[1 1 1].*.60);
  393. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),05), fulldel2time),'color',[1 1 1].*.60);
  394. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),90), fulldel2time),'color',[1 1 1].*.45);
  395. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),10), fulldel2time),'color',[1 1 1].*.45);
  396. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),75), fulldel2time),'color',[1 1 1].*.25);
  397. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),25), fulldel2time),'color',[1 1 1].*.25);
  398. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),65), fulldel2time),'color',[0 0 1].*.1);
  399. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_L(:,1,xx))),35), fulldel2time),'color',[1 1 1].*.1);%ylim([-1 1]);
  400. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  401. subplot(1,2,2);
  402. plotmsem(fulldel2time,nanmedian(squeeze(pooleposxmat_R(:,1,fulldel2time))),'k');
  403. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),99), fulldel2time),'color',[1 1 1].*.85);
  404. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),01), fulldel2time),'color',[1 1 1].*.85);
  405. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),95), fulldel2time),'color',[1 1 1].*.60);
  406. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),05), fulldel2time),'color',[1 1 1].*.60);
  407. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),90), fulldel2time),'color',[1 1 1].*.45);
  408. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),10), fulldel2time),'color',[1 1 1].*.45);
  409. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),75), fulldel2time),'color',[1 1 1].*.25);
  410. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),25), fulldel2time),'color',[1 1 1].*.25);
  411. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),65), fulldel2time),'color',[0 0 1].*.1);
  412. plot(fulldel2time,arrayfun(@(xx) prctile(rmnans(squeeze(pooleposxmat_R(:,1,xx))),35), fulldel2time),'color',[1 1 1].*.1);%ylim([-1 1]);
  413. plotvline([min(eval(selectedTimes)) max(eval(selectedTimes))]); plothline(0); xlim([min(eval(selectedTimes)) max(eval(selectedTimes))]);
  414. end
  415. %%
  416. % fullfig();
  417. % subplot(1,4,1);
  418. % spy(vectorisen(~isnan(poolspksqmat_shLalgn(:,cumsum(nccs),:)),1:2));
  419. % subplot(1,4,2);
  420. % spy(vectorisen(~isnan(poolspksqmat_shRalgn(:,cumsum(nccs),:)),1:2));
  421. % subplot(1,4,3);
  422. % spy(vectorisen(~isnan(pooleposxmat_shLalgn(:,cumsum(nccs),:)),1:2));
  423. % subplot(1,4,4);
  424. % spy(vectorisen(~isnan(pooleposxmat_shRalgn(:,cumsum(nccs),:)),1:2));
  425. % title('Aligned to shifts');
  426. %%
  427. hfig=fullfig(); hfig.Position=[0 0 .5 1];
  428. subplot(2,1,1); ylim([0 100]); hold on
  429. plot(rtmax_ds,squeeze(sum(~isnan(pooleposxmat_L(:,cumsum(nccs),vtps_ds==1))))./repmat(ntrs',1,sum(vtps_ds>0))*100); hold on
  430. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  431. subplot(2,1,2); ylim([0 100]); hold on
  432. plot(rtmax_ds,squeeze(sum(~isnan(pooleposxmat_R(:,cumsum(nccs),vtps_ds==1))))./repmat(ntrs',1,sum(vtps_ds>0))*100); hold on
  433. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  434. legend({'subj 1, sn 1','subj 1, sn 2','subj 1, sn 3','subj 1, sn 4','subj 2, sn 1','subj 2, sn 2','subj 2, sn 3','subj 2, sn 4'},'box','off');
  435. switch selflag
  436. case 1
  437. subplot(2,1,1);
  438. title('Look Left Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  439. subplot(2,1,2);
  440. title('Look Left Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  441. case 2
  442. subplot(2,1,1);
  443. title('Look Right Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  444. subplot(2,1,2);
  445. title('Look Right Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  446. case 3
  447. subplot(2,1,1);
  448. title('Look Left Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  449. subplot(2,1,2);
  450. title('Look Left Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  451. case 4
  452. subplot(2,1,1);
  453. title('Look Right Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  454. subplot(2,1,2);
  455. title('Look Right Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  456. end
  457. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del.png']);
  458. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del.fig']);
  459. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del.svg']);
  460. clearvars pooleposxmat_L pooleposxmat_R
  461. %%
  462. if any(caseflag==[1 2 4 5])
  463. hfig=fullfig(); hfig.Position=[0 0 .5 1];
  464. subplot(2,1,1); ylim([0 100]); hold on; gg=gca;
  465. %plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shLonly(:,cumsum(nccs),:))))./repmat(ntrs',1,Ntps_ds)*100); hold on
  466. pp=plot(eval(selectedTimes),squeeze(sum(~isnan(poolspksqmat_shLonly(:,cumsum(nccs),eval(selectedTimes)))))./repmat(ntrs',1,length(eval(selectedTimes)))*100); hold on
  467. for jj=1:8
  468. plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shLonly(:,sum(nccs(1:jj)),:))))./repmat(ntrs(jj)',1,Ntps_ds)*100,':','color',pp(jj).Color); hold on
  469. end
  470. for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  471. %xlim([189 438]);%xlim([1 Ntps_ds]);
  472. subplot(2,1,2); ylim([0 100]); hold on
  473. %plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shRonly(:,cumsum(nccs),:))))./repmat(ntrs',1,Ntps_ds)*100); hold on
  474. pp=plot(eval(selectedTimes),squeeze(sum(~isnan(poolspksqmat_shRonly(:,cumsum(nccs),eval(selectedTimes)))))./repmat(ntrs',1,length(eval(selectedTimes)))*100); hold on
  475. for jj=1:8
  476. plot(1:Ntps_ds,squeeze(sum(~isnan(poolspksqmat_shRonly(:,sum(nccs(1:jj)),:))))./repmat(ntrs(jj)',1,Ntps_ds)*100,':','color',pp(jj).Color); hold on
  477. end
  478. for jj=1:7; plotvline(ntce_ds(jj,1:2)); tt=text(ntce_ds(jj,1),.85*max(get(gca,'YLim')),twLabels{jj},'Rotation',90); end
  479. legend({'subj 1, sn 1','subj 1, sn 2','subj 1, sn 3','subj 1, sn 4','subj 2, sn 1','subj 2, sn 2','subj 2, sn 3','subj 2, sn 4'},'box','off');
  480. %xlim([189 438]);%xlim([1 Ntps_ds]);
  481. switch selflag
  482. case 1
  483. subplot(2,1,1);
  484. title('Look Left Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  485. subplot(2,1,2);
  486. title('Look Left Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  487. case 2
  488. subplot(2,1,1);
  489. title('Look Right Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  490. subplot(2,1,2);
  491. title('Look Right Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  492. case 3
  493. subplot(2,1,1);
  494. title('Look Left Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  495. subplot(2,1,2);
  496. title('Look Left Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  497. case 4
  498. subplot(2,1,1);
  499. title('Look Right Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  500. subplot(2,1,2);
  501. title('Look Right Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  502. end
  503. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_shifts.png']);
  504. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_shifts.fig']);
  505. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_shifts.svg']);
  506. end
  507. % subplot(1,4,2);
  508. % spy(vectorisen(~isnan(poolspksqmat_shRalgn(:,cumsum(nccs),:)),1:2));
  509. % subplot(1,4,3);
  510. % spy(vectorisen(~isnan(pooleposxmat_shLalgn(:,cumsum(nccs),:)),1:2));
  511. % subplot(1,4,4);
  512. % spy(vectorisen(~isnan(pooleposxmat_shRalgn(:,cumsum(nccs),:)),1:2));
  513. % title('Aligned to shifts');
  514. % SET ALIGNMENT
  515. % figure('units','normalized','position',[0 0 1 1]);
  516. % subplot(2,1,1); shtr=1:length(isSR); plot(rerange(ccpex(isSR(shtr),:)',ccpex(:))); hold on
  517. % plot(stR(shtr),arrayfun(@(xx) rerange(ccpex(isSR(xx),stR(xx)),ccpex(:)), shtr),'rx');
  518. % plot(get(gca,'XLim'),[0 0],'k:'); ylim([-1 1]); title(sprintf('sample cell, shift R detection, n_s_h_R=%d', sum(nuR)));
  519. %
  520. % subplot(2,1,2); shtr=1:length(isSL); plot(rerange(ccpex(isSL(shtr),:)',ccpex(:))); hold on
  521. % plot(stL(shtr),arrayfun(@(xx) rerange(ccpex(isSL(xx),stL(xx)),ccpex(:)), shtr),'rx');
  522. % plot(get(gca,'XLim'),[0 0],'k:'); ylim([-1 1]); title(sprintf('sample cell, shift L detection, n_s_h_L=%d', sum(nuL)));
  523. %
  524. % %
  525. % figure('units','normalized','position',[0 0 1 1]);
  526. % subplot(2,1,1);
  527. % plot(vectorisen(pooleposxmat_shRalgn(:,end,:),1:2)'./max(abs(pooleposxmat_shRalgn(:)))); hold on;
  528. % plot(get(gca,'XLim'),[0 0],'k:'); ylim([-1 1]); title(sprintf('sample cell, shift R detection, n_s_h_R=%d', sum(nuR)));
  529. %
  530. % subplot(2,1,2);
  531. % plot(vectorisen(pooleposxmat_shLalgn(:,end,:),1:2)'./max(abs(pooleposxmat_shLalgn(:)))); hold on;
  532. % plot(get(gca,'XLim'),[0 0],'k:'); ylim([-1 1]); title(sprintf('sample cell, shift L detection, n_s_h_L=%d', sum(nuL)));
  533. % firstL offer1 - thenR delay2
  534. % firstR offer1 - thenL delay2
  535. % firstR offer1 - thenR delay2
  536. %%
  537. if 0
  538. % re-defined on vtps_ds
  539. o1LLinterval=20; %x10ms=200ms
  540. d1LRinterval=20; %x10ms=200ms
  541. o2LRinterval=20; %x10ms=200ms
  542. d2LLinterval=20; %x10ms=200ms
  543. chLLinterval=44;
  544. Offer1LLtime=sum(rtmes_ds(1:2))-o1LLinterval+(1:o1LLinterval);
  545. Delay1LRtime=sum(rtmes_ds(1:3))-d1LRinterval+(1:d1LRinterval);
  546. Offer2LRtime=sum(rtmes_ds(1:4))-o2LRinterval+(1:o2LRinterval);
  547. Delay2LLtime=sum(rtmes_ds(1:5))-d2LLinterval+(1:d2LLinterval);
  548. ChoiceLLtime=sum(rtmes_ds(1:8))-chLLinterval+(1:chLLinterval);
  549. pooleposxmat_vds=pooleposxmat_ds(:,:,vtps_ds==1);
  550. pooleposxmat_vrds=rmnans(vectorisen(pooleposxmat_ds(:,cumsum(nccs),vtps_ds==1),1:2));
  551. xvro1LL=vectorise(nanmean(pooleposxmat_vrds(:,Offer1LLtime),2)<0);
  552. xvrd1LR=vectorise(nanmean(pooleposxmat_vrds(:,Delay1LRtime),2)>0);
  553. xvro2LR=vectorise(nanmean(pooleposxmat_vrds(:,Offer2LRtime),2)>0);
  554. xvrd2LL=vectorise(nanmean(pooleposxmat_vrds(:,Delay2LLtime),2)<0);
  555. xvrchLL=vectorise(nanmean(pooleposxmat_vrds(:,ChoiceLLtime),2)<0);
  556. pooleposxmat_vrdds=pooleposxmat_vrds;
  557. pooleposxmat_vrdds(rmnans(vectorise(pooloffer1sd(:,cumsum(nccs))))==0,:)=...
  558. -pooleposxmat_vrdds(rmnans(vectorise(pooloffer1sd(:,cumsum(nccs))))==0,:);
  559. xvrdo1LL=vectorise(nanmean(pooleposxmat_vrdds(:,Offer1LLtime),2)<0);
  560. xvrdd1LR=vectorise(nanmean(pooleposxmat_vrdds(:,Delay1LRtime),2)>0);
  561. xvrdo2LR=vectorise(nanmean(pooleposxmat_vrdds(:,Offer2LRtime),2)>0);
  562. xvrdd2LL=vectorise(nanmean(pooleposxmat_vrdds(:,Delay2LLtime),2)<0);
  563. xvrdchLL=vectorise(nanmean(pooleposxmat_vrdds(:,ChoiceLLtime),2)<0);
  564. xo1LL=vectorise(nanmean(pooleposxmat_vds(:,:,Offer1LLtime),3)<0);
  565. xo1LR=vectorise(nanmean(pooleposxmat_vds(:,:,Offer1LLtime),3)>0);
  566. xd1LR=vectorise(nanmean(pooleposxmat_vds(:,:,Delay1LRtime),3)>0);
  567. xo2LR=vectorise(nanmean(pooleposxmat_vds(:,:,Offer2LRtime),3)>0);
  568. xd2LL=vectorise(nanmean(pooleposxmat_vds(:,:,Delay2LLtime),3)<0);
  569. vvss=vectorisen(pooleposxmat_vds,1:2);
  570. vvrss=(pooleposxmat_vrds);
  571. iso1LL=nanmean(pooleposxmat_vds(:,:,Offer1LLtime),3)<0;
  572. isd1LR=nanmean(pooleposxmat_vds(:,:,Delay1LRtime),3)>0;
  573. iso2LR=nanmean(pooleposxmat_vds(:,:,Offer2LRtime),3)>0;
  574. isd2LL=nanmean(pooleposxmat_vds(:,:,Delay2LLtime),3)<0;
  575. iso1LLd2LL= iso1LL & isd2LL;
  576. iso1LLd1LR= iso1LL &(~isd2LL);
  577. iso1LLd1LLd2LL= iso1LL & (~isd1LR) & isd2LL;
  578. iso1LLd1LLd2LR= iso1LL & (~isd1LR) &(~isd2LL);
  579. iso2LRd2LL= iso2LR & isd2LL;
  580. iso2LRd2LR= iso2LR &(~isd2LL);
  581. iso2LLd2LL=(~iso2LR)& isd2LL;
  582. iso2LLd2LR=(~iso2LR)&(~isd2LL);
  583. xebins=linspace(-max(abs(vvss(:))),max(abs(vvss(:))),1e3);
  584. firstL =logical(rmnans(vectorise(pooloffer1sd(:,cumsum(nccs))))==1);
  585. firstR =logical(rmnans(vectorise(pooloffer1sd(:,cumsum(nccs))))==0);
  586. chooseR =logical(rmnans(vectorise(poolofferchR(:,cumsum(nccs))))==1);
  587. %%
  588. % offer1sd==1 if L; 0 if R.
  589. clc
  590. fprintf('LookL on offer1 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdo1LL(firstL))==1 ])*100);
  591. fprintf('LookR on offer1 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdo1LL(firstL))==0 ])*100);
  592. fprintf('LookL on offer1 %2.2f%% of the trials where first offer is Right.\n', mean([double(xvrdo1LL(firstR))==1 ])*100);
  593. fprintf('LookR on offer1 %2.2f%% of the trials where first offer is Right.\n\n',mean([double(xvrdo1LL(firstR))==0 ])*100);
  594. fprintf('LookL on delay1 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdd1LR(firstL))==0 ])*100);
  595. fprintf('LookR on delay1 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdd1LR(firstL))==1 ])*100);
  596. fprintf('LookL on delay1 %2.2f%% of the trials where first offer is Right.\n', mean([double(xvrdd1LR(firstR))==0 ])*100);
  597. fprintf('LookR on delay1 %2.2f%% of the trials where first offer is Right.\n\n',mean([double(xvrdd1LR(firstR))==1 ])*100);
  598. fprintf('LookL on offer2 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdo2LR(firstL))==0 ])*100);
  599. fprintf('LookR on offer2 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdo2LR(firstL))==1 ])*100);
  600. fprintf('LookL on offer2 %2.2f%% of the trials where first offer is Right.\n', mean([double(xvrdo2LR(firstR))==0 ])*100);
  601. fprintf('LookR on offer2 %2.2f%% of the trials where first offer is Right.\n\n',mean([double(xvrdo2LR(firstR))==1 ])*100);
  602. fprintf('LookL on delay2 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdd2LL(firstL))==1 ])*100);
  603. fprintf('LookR on delay2 %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdd2LL(firstL))==0 ])*100);
  604. fprintf('LookL on delay2 %2.2f%% of the trials where first offer is Right.\n', mean([double(xvrdd2LL(firstR))==1 ])*100);
  605. fprintf('LookR on delay2 %2.2f%% of the trials where first offer is Right.\n\n',mean([double(xvrdd2LL(firstR))==0 ])*100);
  606. fprintf('LookL on choice %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdchLL(firstL))==1 ])*100);
  607. fprintf('LookR on choice %2.2f%% of the trials where first offer is Left.\n', mean([double(xvrdchLL(firstL))==0 ])*100);
  608. fprintf('LookL on choice %2.2f%% of the trials where first offer is Right.\n', mean([double(xvrdchLL(firstR))==1 ])*100);
  609. fprintf('LookR on choice %2.2f%% of the trials where first offer is Right.\n\n',mean([double(xvrdchLL(firstR))==0 ])*100);
  610. %%
  611. Fisbest =logical(rmnans(vectorise(pooloffer1ev(:,cumsum(nccs)))) >rmnans(vectorise(pooloffer2ev(:,cumsum(nccs)))));
  612. Sisbest =logical(rmnans(vectorise(pooloffer1ev(:,cumsum(nccs)))) <rmnans(vectorise(pooloffer2ev(:,cumsum(nccs)))));
  613. FSssame =logical(rmnans(vectorise(pooloffer1ev(:,cumsum(nccs))))==rmnans(vectorise(pooloffer2ev(:,cumsum(nccs)))));
  614. Lisbest_reref= logical([Fisbest & firstL; Fisbest & firstR]);
  615. Risbest_reref= logical([Sisbest & firstL; Sisbest & firstR]);
  616. chR_reref=logical([chooseR==1 & firstL; chooseR==0 & firstR]);
  617. clc
  618. % LookL and Lis best means LookL(firstL&Fisbest) + LookR(firstR&Risbest)
  619. % LL fL fLbest - LL fR fRbest - LL fL SRbest - LL fR SLbest
  620. % LL fL fLbest - LL fL fLbest - LR fL fRbest - LL fL
  621. fprintf('LookL on offer1 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdo1LL(Fisbest & firstL)==1) double(xvrdo1LL(Fisbest & firstR)==0)])*100);
  622. fprintf('LookL on offer1 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdo1LL(Sisbest & firstL)==1) double(xvrdo1LL(Sisbest & firstR)==0)])*100);
  623. fprintf('LookL on offer1 %2.2f%% of the trials where first, left offer is same.\n', mean([double(xvrdo1LL(firstL & FSssame)==1) double(xvrdo1LL(firstR & FSssame)==0)])*100);
  624. fprintf('LookR on offer1 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdo1LL(Fisbest & firstL)==0) double(xvrdo1LL(Fisbest & firstR)==1)])*100);
  625. fprintf('LookR on offer1 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdo1LL(Sisbest & firstL)==0) double(xvrdo1LL(Sisbest & firstR)==1)])*100);
  626. fprintf('LookR on offer1 %2.2f%% of the trials where first, left offer is same.\n\n',mean([double(xvrdo1LL(firstL & FSssame)==0) double(xvrdo1LL(firstR & FSssame)==1)])*100);
  627. fprintf('LookL on delay1 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdd1LR(Fisbest & firstL)==0) double(xvrdd1LR(Fisbest & firstR)==1)])*100);
  628. fprintf('LookL on delay1 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdd1LR(Sisbest & firstL)==0) double(xvrdd1LR(Sisbest & firstR)==1)])*100);
  629. fprintf('LookL on delay1 %2.2f%% of the trials where first, left offer is same.\n', mean([double(xvrdd1LR(firstL & FSssame)==0) double(xvrdd1LR(firstR & FSssame)==1)])*100);
  630. fprintf('LookR on delay1 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdd1LR(Fisbest & firstL)==1) double(xvrdd1LR(Fisbest & firstR)==0)])*100);
  631. fprintf('LookR on delay1 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdd1LR(Sisbest & firstL)==1) double(xvrdd1LR(Sisbest & firstR)==0)])*100);
  632. fprintf('LookR on delay1 %2.2f%% of the trials where first, left offer is same.\n\n',mean([double(xvrdd1LR(firstL & FSssame)==1) double(xvrdd1LR(firstR & FSssame)==0)])*100);
  633. fprintf('LookL on offer2 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdo2LR(Fisbest & firstL)==0) double(xvrdo2LR(Fisbest & firstR)==1)])*100);
  634. fprintf('LookL on offer2 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdo2LR(Sisbest & firstL)==0) double(xvrdo2LR(Sisbest & firstR)==1)])*100);
  635. fprintf('LookL on offer2 %2.2f%% of the trials where first, left offer is same.\n', mean([double(xvrdo2LR(firstL & FSssame)==0) double(xvrdo2LR(firstR & FSssame)==1)])*100);
  636. fprintf('LookR on offer2 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdo2LR(Fisbest & firstL)==1) double(xvrdo2LR(Fisbest & firstR)==0)])*100);
  637. fprintf('LookR on offer2 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdo2LR(Sisbest & firstL)==1) double(xvrdo2LR(Sisbest & firstR)==0)])*100);
  638. fprintf('LookR on offer2 %2.2f%% of the trials where first, left offer is same.\n\n',mean([double(xvrdo2LR(firstL & FSssame)==1) double(xvrdo2LR(firstR & FSssame)==0)])*100);
  639. fprintf('LookL on delay2 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdd2LL(Fisbest & firstL)==1) double(xvrdd2LL(Fisbest & firstR)==0)])*100);
  640. fprintf('LookL on delay2 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdd2LL(Sisbest & firstL)==1) double(xvrdd2LL(Sisbest & firstR)==0)])*100);
  641. fprintf('LookL on delay2 %2.2f%% of the trials where first, left offer is same.\n', mean([double(xvrdd2LL(firstL & FSssame)==1) double(xvrdd2LL(firstR & FSssame)==0)])*100);
  642. fprintf('LookR on delay2 %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdd2LL(Fisbest & firstL)==0) double(xvrdd2LL(Fisbest & firstR)==1)])*100);
  643. fprintf('LookR on delay2 %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdd2LL(Sisbest & firstL)==0) double(xvrdd2LL(Sisbest & firstR)==1)])*100);
  644. fprintf('LookR on delay2 %2.2f%% of the trials where first, left offer is same.\n\n',mean([double(xvrdd2LL(firstL & FSssame)==0) double(xvrdd2LL(firstR & FSssame)==1)])*100);
  645. fprintf('LookL on choice %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdchLL(Fisbest & firstL)==1) double(xvrdchLL(Fisbest & firstR)==0)])*100);
  646. fprintf('LookL on choice %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdchLL(Sisbest & firstL)==1) double(xvrdchLL(Sisbest & firstR)==0)])*100);
  647. fprintf('LookL on choice %2.2f%% of the trials where first, left offer is same.\n', mean([double(xvrdchLL(firstL & FSssame)==1) double(xvrdchLL(firstR & FSssame)==0)])*100);
  648. fprintf('LookR on choice %2.2f%% of the trials where first, left offer is best.\n', mean([double(xvrdchLL(Fisbest & firstL)==0) double(xvrdchLL(Fisbest & firstR)==1)])*100);
  649. fprintf('LookR on choice %2.2f%% of the trials where first, left offer is worse.\n', mean([double(xvrdchLL(Sisbest & firstL)==0) double(xvrdchLL(Sisbest & firstR)==1)])*100);
  650. fprintf('LookR on choice %2.2f%% of the trials where first, left offer is same.\n\n',mean([double(xvrdchLL(firstL & FSssame)==0) double(xvrdchLL(firstR & FSssame)==1)])*100);
  651. %%
  652. clc
  653. fprintf('LookL on offer1 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdo1LL(firstL & chooseR==0))==1 double(xvrdo1LL(firstR & chooseR==1))==0])*100);
  654. fprintf('LookR on offer1 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdo1LL(firstL & chooseR==0))==0 double(xvrdo1LL(firstR & chooseR==1))==1])*100);
  655. fprintf('LookL on offer1 %2.2f%% of the trials where chosen offer is Right.\n', mean([double(xvrdo1LL(firstL & chooseR==1))==1 double(xvrdo1LL(firstR & chooseR==0))==0])*100);
  656. fprintf('LookR on offer1 %2.2f%% of the trials where chosen offer is Right.\n\n',mean([double(xvrdo1LL(firstL & chooseR==1))==0 double(xvrdo1LL(firstR & chooseR==0))==1])*100);
  657. fprintf('LookL on delay1 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdd1LR(firstL & chooseR==0))==0 double(xvrdd1LR(firstR & chooseR==1))==1])*100);
  658. fprintf('LookR on delay1 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdd1LR(firstL & chooseR==0))==1 double(xvrdd1LR(firstR & chooseR==1))==0])*100);
  659. fprintf('LookL on delay1 %2.2f%% of the trials where chosen offer is Right.\n', mean([double(xvrdd1LR(firstL & chooseR==1))==0 double(xvrdd1LR(firstR & chooseR==0))==1])*100);
  660. fprintf('LookR on delay1 %2.2f%% of the trials where chosen offer is Right.\n\n',mean([double(xvrdd1LR(firstL & chooseR==1))==1 double(xvrdd1LR(firstR & chooseR==0))==0])*100);
  661. fprintf('LookL on offer2 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdo2LR(firstL & chooseR==0))==0 double(xvrdo2LR(firstR & chooseR==1))==1])*100);
  662. fprintf('LookR on offer2 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdo2LR(firstL & chooseR==0))==1 double(xvrdo2LR(firstR & chooseR==1))==0])*100);
  663. fprintf('LookL on offer2 %2.2f%% of the trials where chosen offer is Right.\n', mean([double(xvrdo2LR(firstL & chooseR==1))==0 double(xvrdo2LR(firstR & chooseR==0))==1])*100);
  664. fprintf('LookR on offer2 %2.2f%% of the trials where chosen offer is Right.\n\n',mean([double(xvrdo2LR(firstL & chooseR==1))==1 double(xvrdo2LR(firstR & chooseR==0))==0])*100);
  665. fprintf('LookL on delay2 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdd2LL(firstL & chooseR==0))==1 double(xvrdd2LL(firstR & chooseR==1))==0])*100);
  666. fprintf('LookR on delay2 %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdd2LL(firstL & chooseR==0))==0 double(xvrdd2LL(firstR & chooseR==1))==1])*100);
  667. fprintf('LookL on delay2 %2.2f%% of the trials where chosen offer is Right.\n', mean([double(xvrdd2LL(firstL & chooseR==1))==1 double(xvrdd2LL(firstR & chooseR==0))==0])*100);
  668. fprintf('LookR on delay2 %2.2f%% of the trials where chosen offer is Right.\n\n',mean([double(xvrdd2LL(firstL & chooseR==1))==0 double(xvrdd2LL(firstR & chooseR==0))==1])*100);
  669. fprintf('LookL on choice %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdchLL(firstL & chooseR==0))==1 double(xvrdchLL(firstR & chooseR==1))==0])*100);
  670. fprintf('LookR on choice %2.2f%% of the trials where chosen offer is Left.\n', mean([double(xvrdchLL(firstL & chooseR==0))==0 double(xvrdchLL(firstR & chooseR==1))==1])*100);
  671. fprintf('LookL on choice %2.2f%% of the trials where chosen offer is Right.\n', mean([double(xvrdchLL(firstL & chooseR==1))==1 double(xvrdchLL(firstR & chooseR==0))==0])*100);
  672. fprintf('LookR on choice %2.2f%% of the trials where chosen offer is Right.\n\n',mean([double(xvrdchLL(firstL & chooseR==1))==0 double(xvrdchLL(firstR & chooseR==0))==1])*100);
  673. %%
  674. fullfig();
  675. subplot(3,1,1);
  676. %SUBJECTS1&2
  677. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(:,tt),xebins,'Normalization', 'probability'); end
  678. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  679. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  680. plot([0 sum(rtmes_ds)],[0 0],'k:');
  681. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  682. subplot(3,1,2);
  683. %SUBJECT1
  684. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vectorise(pooleposxmat_vds(:,1:sum(nccs(1:4)),tt)),xebins,'Normalization', 'probability'); end
  685. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  686. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  687. plot([0 sum(rtmes_ds)],[0 0],'k:');
  688. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  689. subplot(3,1,3);
  690. %SUBJECT2
  691. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vectorise(pooleposxmat_vds(:,sum(nccs(1:4))+1:end,tt)),xebins,'Normalization', 'probability'); end
  692. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  693. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  694. plot([0 sum(rtmes_ds)],[0 0],'k:');
  695. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  696. %%
  697. fullfig();
  698. subplot(3,1,1);
  699. %SUBJECTS1&2
  700. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vectorise(pooleposxmat_vrdds(:,tt)),xebins,'Normalization', 'probability'); end
  701. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  702. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  703. plot([0 sum(rtmes_ds)],[0 0],'k:');
  704. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  705. subplot(3,1,2);
  706. %SUBJECT1
  707. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vectorise(pooleposxmat_vrdds(1:sum(ntrs(1:4)),tt)),xebins,'Normalization', 'probability'); end
  708. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  709. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  710. plot([0 sum(rtmes_ds)],[0 0],'k:');
  711. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  712. subplot(3,1,3);
  713. %SUBJECT2
  714. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vectorise(pooleposxmat_vrdds(sum(ntrs(1:4))+1:end,tt)),xebins,'Normalization', 'probability'); end
  715. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  716. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  717. plot([0 sum(rtmes_ds)],[0 0],'k:');
  718. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  719. %%
  720. fullfig();
  721. subplot(2,1,1);
  722. % LOOK LEFT DURING OFFER1
  723. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(xvro1LL,tt),xebins,'Normalization', 'probability'); end
  724. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  725. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  726. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Offer1LLtime(1),-10000,sprintf('LookL:%2.2f%%',mean(xvro1LL)*100),'color','r');
  727. plot([1 1].*Offer1LLtime(1),get(gca,'YLim'),'r:');
  728. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  729. subplot(2,1,2);
  730. %LOOK RIGHT DURING OFFER1
  731. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(~xvro1LL,tt),xebins,'Normalization', 'probability'); end
  732. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  733. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  734. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Offer1LLtime(1),+10000,sprintf('LookR:%2.2f%%',mean(~xvro1LL)*100),'color','r');
  735. plot([1 1].*Offer1LLtime(1),get(gca,'YLim'),'r:');
  736. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  737. supertitle('Compare offer1 side: LookL (top), LookR (bottom)');
  738. %%
  739. fullfig();
  740. subplot(2,1,1);
  741. % LOOK RIGHT DURING DELAY1
  742. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(xvrd1LR,tt),xebins,'Normalization', 'probability'); end
  743. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  744. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  745. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Delay1LRtime(1),+10000,sprintf('LookR:%2.2f%%',mean(xvrd1LR)*100),'color','r');
  746. plot([1 1].*Delay1LRtime(1),get(gca,'YLim'),'r:');
  747. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  748. subplot(2,1,2);
  749. %LOOK LEFT DURING DELAY1
  750. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(~xvrd1LR,tt),xebins,'Normalization', 'probability'); end
  751. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  752. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  753. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Delay1LRtime(1),-10000,sprintf('LookL:%2.2f%%',mean(~xvrd1LR)*100),'color','r');
  754. plot([1 1].*Delay1LRtime(1),get(gca,'YLim'),'r:');
  755. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  756. supertitle('Compare delay1 side: LookR (top), LookL (bottom)');
  757. %%
  758. fullfig();
  759. subplot(2,1,1);
  760. % LOOK LEFT DURING OFFER1 AND LEFT DURING DELAY2
  761. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(xvro1LL&(~xvrd1LR)&xvrd2LL,tt),xebins,'Normalization', 'probability'); end
  762. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  763. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  764. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Delay2LLtime(1),-10000,sprintf('LookL:%2.2f%%',mean(xvro1LL&(~xvrd1LR)&xvrd2LL)*100),'color','r');
  765. plot([1 1].*Offer1LLtime(1),get(gca,'YLim'),'r:');
  766. plot([1 1].*Delay1LRtime(1),get(gca,'YLim'),'r:');
  767. plot([1 1].*Delay2LLtime(1),get(gca,'YLim'),'r:');
  768. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  769. subplot(2,1,2);
  770. %LOOK LEFT DURING OFFER1 AND RIGHT DURING DELAY2
  771. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvss(xvro1LL&(~xvrd1LR)&(~xvrd2LL),tt),xebins,'Normalization', 'probability'); end
  772. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  773. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:jj-1)),max(get(gca,'YLim')),twLabels{jj}); end
  774. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Delay2LLtime(1),+10000,sprintf('LookR:%2.2f%%',mean(xvro1LL&(~xvrd1LR)&(~xvrd2LL))*100),'color','r');
  775. plot([1 1].*Offer1LLtime(1),get(gca,'YLim'),'r:');
  776. plot([1 1].*Delay1LRtime(1),get(gca,'YLim'),'r:');
  777. plot([1 1].*Delay2LLtime(1),get(gca,'YLim'),'r:');
  778. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  779. supertitle('offer1 LookL, delay1 LookL, compare delay2 side: LookL (top), LookR (bottom)');
  780. %%
  781. Vpl(1,:)=( xvro1LL)&(~xvrd1LR);% offer1=L delay1=L
  782. Vpl(2,:)=( xvro1LL)&( xvrd1LR);% offer1=L delay1=R
  783. Vpl(3,:)=(~xvro1LL)&(~xvrd1LR);% offer1=R delay1=L
  784. Vpl(4,:)=(~xvro1LL)&( xvrd1LR);% offer1=R delay1=R
  785. Vpl(5,:)=(~xvro2LR)&( xvrd2LL);% offer2=L delay1=L
  786. Vpl(6,:)=(~xvro2LR)&(~xvrd2LL);% offer2=L delay1=R
  787. Vpl(7,:)=( xvro2LR)&( xvrd2LL);% offer2=R delay1=L
  788. Vpl(8,:)=( xvro2LR)&(~xvrd2LL);% offer2=R delay1=R
  789. Spl={'Off1L,Del1L=','Off1L,Del1R=','Off1R,Del1L=','Off1R,Del1R=',...
  790. 'Off2L,Del2L=','off2L,Del2R=','Off2R,Del2L=','Off2R,Del2R='};
  791. Ppl=[0 0; 0 1; 1 0; 1 1];
  792. for jj=[1 3 5 7]
  793. fullfig([Ppl((jj+1)/2,:)*.5 .5 .5]);
  794. subplot(2,1,1);
  795. % LOOK RIGHT DURING OFFER2 AND LEFT DURING DELAY2
  796. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(Vpl(jj,:),tt),xebins,'Normalization', 'probability'); end
  797. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  798. for tt=1:8; plot([1 1].*sum(rtmes_ds(1:tt)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:tt-1)),max(get(gca,'YLim')),twLabels{tt}); end
  799. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Delay2LLtime(1),-10000,sprintf('%s:%2.2f%%',Spl{jj},mean(Vpl(jj,:))*100),'color','r');
  800. plot([1 1].*Offer2LRtime(1),get(gca,'YLim'),'r:');
  801. plot([1 1].*Delay2LLtime(1),get(gca,'YLim'),'r:');
  802. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  803. subplot(2,1,2);
  804. %LOOK RIGHT DURING OFFER2 AND RIGHT DURING DELAY2
  805. for tt=1:Nvtps_ds; [hc(:,tt),he]=histcounts(vvrss(Vpl(jj+1,:),tt),xebins,'Normalization', 'probability'); end
  806. imagesc(rtmax_ds,he,hc); colormap(getdivergentcolmap(repmat(1:-.25:0,3,1)',[8 16 32 128])); hold on; view(2)
  807. for tt=1:8; plot([1 1].*sum(rtmes_ds(1:tt)),get(gca,'YLim'),'k:'); text(sum(rtmes_ds(1:tt-1)),max(get(gca,'YLim')),twLabels{tt}); end
  808. plot([0 sum(rtmes_ds)],[0 0],'k:'); text(Delay2LLtime(1),+10000,sprintf('%s:%2.2f%%',Spl{jj+1},mean(Vpl(jj+1,:))*100),'color','r');
  809. plot([1 1].*Offer2LRtime(1),get(gca,'YLim'),'r:');
  810. plot([1 1].*Delay2LLtime(1),get(gca,'YLim'),'r:');
  811. xlabel('time bins (10 ms)'); ylabel('eye pos. (<0 is L; >0 is R)');
  812. end
  813. end
  814. %% Regress EV vs Spiking
  815. close all;
  816. if recomputelm
  817. lmELpv=nan(Nccs,Ntps_ds); lmELpv_shf=nan(Nccs,Ntps_ds,Nshf); lmERpv=nan(Nccs,Ntps_ds); lmERpv_shf=nan(Nccs,Ntps_ds,Nshf);
  818. lmELpvLL=nan(Nccs,Ntps_ds); lmELpvLL_shf=nan(Nccs,Ntps_ds,Nshf); lmERpvLL=nan(Nccs,Ntps_ds); lmERpvLL_shf=nan(Nccs,Ntps_ds,Nshf);
  819. lmELpvLR=nan(Nccs,Ntps_ds); lmELpvLR_shf=nan(Nccs,Ntps_ds,Nshf); lmERpvLR=nan(Nccs,Ntps_ds); lmERpvLR_shf=nan(Nccs,Ntps_ds,Nshf);
  820. lmELR2=nan(Nccs,Ntps_ds); lmELR2_shf=nan(Nccs,Ntps_ds,Nshf); lmERR2=nan(Nccs,Ntps_ds); lmERR2_shf=nan(Nccs,Ntps_ds,Nshf);
  821. lmELR2LL=nan(Nccs,Ntps_ds); lmELR2LL_shf=nan(Nccs,Ntps_ds,Nshf); lmERR2LL=nan(Nccs,Ntps_ds); lmERR2LL_shf=nan(Nccs,Ntps_ds,Nshf);
  822. lmELR2LR=nan(Nccs,Ntps_ds); lmELR2LR_shf=nan(Nccs,Ntps_ds,Nshf); lmERR2LR=nan(Nccs,Ntps_ds); lmERR2LR_shf=nan(Nccs,Ntps_ds,Nshf);
  823. lmELb0=nan(Nccs,Ntps_ds); lmELb0_shf=nan(Nccs,Ntps_ds,Nshf); lmERb0=nan(Nccs,Ntps_ds); lmERb0_shf=nan(Nccs,Ntps_ds,Nshf);
  824. lmELb0LL=nan(Nccs,Ntps_ds); lmELb0LL_shf=nan(Nccs,Ntps_ds,Nshf); lmERb0LL=nan(Nccs,Ntps_ds); lmERb0LL_shf=nan(Nccs,Ntps_ds,Nshf);
  825. lmELb0LR=nan(Nccs,Ntps_ds); lmELb0LR_shf=nan(Nccs,Ntps_ds,Nshf); lmERb0LR=nan(Nccs,Ntps_ds); lmERb0LR_shf=nan(Nccs,Ntps_ds,Nshf);
  826. lmELb1=nan(Nccs,Ntps_ds); lmELb1_shf=nan(Nccs,Ntps_ds,Nshf); lmERb1=nan(Nccs,Ntps_ds); lmERb1_shf=nan(Nccs,Ntps_ds,Nshf);
  827. lmELb1LL=nan(Nccs,Ntps_ds); lmELb1LL_shf=nan(Nccs,Ntps_ds,Nshf); lmERb1LL=nan(Nccs,Ntps_ds); lmERb1LL_shf=nan(Nccs,Ntps_ds,Nshf);
  828. lmELb1LR=nan(Nccs,Ntps_ds); lmELb1LR_shf=nan(Nccs,Ntps_ds,Nshf); lmERb1LR=nan(Nccs,Ntps_ds); lmERb1LR_shf=nan(Nccs,Ntps_ds,Nshf);
  829. lmntrsLL=nan(Nccs,Ntps_ds); lmntrsLR=nan(Nccs,Ntps_ds); lmntrsLL_nn=nan(Nccs,Ntps_ds); lmntrsLR_nn=nan(Nccs,Ntps_ds); lmntrsLL_nn_shLalgn=nan(Nccs,Ntps_ds); lmntrsLR_nn_shRalgn=nan(Nccs,Ntps_ds);
  830. for cc=1:Nccs
  831. ccoff1rw=pooloffer1rw(:,cc);
  832. ccoff2rw=pooloffer2rw(:,cc);
  833. ccoff1ev=pooloffer1ev(:,cc);
  834. ccoff2ev=pooloffer2ev(:,cc);
  835. ccspk=squeeze(poolspksqmat_ds_bln(:,cc,:)); % For linear fit
  836. %%%%% ccspk=squeeze(poolspksqmat_ds(:,cc,:)); % For Poisson fit
  837. ccepx=squeeze(pooleposxmat_ds_bln(:,cc,:));
  838. %%% shift aligned
  839. ccspk_shLalgn=squeeze(poolspksqmat_shLalgn(:,cc,:));
  840. ccspk_shRalgn=squeeze(poolspksqmat_shRalgn(:,cc,:));
  841. ccepx_shLalgn=squeeze(pooleposxmat_shLalgn(:,cc,:));
  842. ccepx_shRalgn=squeeze(pooleposxmat_shRalgn(:,cc,:));
  843. ccisdelSL=isdelSL(:,cc);
  844. ccisdelSR=isdelSR(:,cc);
  845. % cciso1LLd2LL=iso1LLd2LL(:,cc);
  846. % cciso1LLd2LR=iso1LLd2LR(:,cc);
  847. %cciso1LLd1LLd2LL=iso1LLd1LLd2LL(:,cc);
  848. %cciso1LLd1LLd2LR=iso1LLd1LLd2LR(:,cc);
  849. % cciso2LRd2LL=iso2LRd2LL(:,cc);
  850. % cciso2LLd2LL=iso2LLd2LL(:,cc);
  851. % cciso2LRd2LR=iso2LRd2LR(:,cc);
  852. % cciso2LLd2LR=iso2LLd2LR(:,cc);
  853. rmallnans=isnan(ccoff1ev);
  854. rmtrials=rmallnans;%(rmallnans | ccoff1rw~=1 | ccoff2rw~=1);
  855. %ccspk(rmallnans,:)=[];
  856. %ccepx(rmallnans,:)=[];
  857. %ccoff1ev(rmallnans)=[];
  858. %ccoff2ev(rmallnans)=[];
  859. ccspk(rmtrials,:)=[];
  860. ccepx(rmtrials,:)=[];
  861. ccoff1ev(rmtrials)=[];
  862. ccoff2ev(rmtrials)=[];
  863. ccoff1rw(rmtrials)=[];
  864. ccoff2rw(rmtrials)=[];
  865. %cciso2LRd2LL(rmtrials)=[];
  866. %cciso2LRd2LR(rmtrials)=[];
  867. %cciso2LLd2LL(rmtrials)=[];
  868. %cciso2LLd2LR(rmtrials)=[];
  869. %cciso1LLd1LLd2LL(rmtrials)=[];
  870. %cciso1LLd1LLd2LR(rmtrials)=[];
  871. ccisdelSL(rmtrials)=[];
  872. ccisdelSR(rmtrials)=[];
  873. ccspk_shLalgn(rmtrials,:)=[];
  874. ccspk_shRalgn(rmtrials,:)=[];
  875. ccepx_shLalgn(rmtrials,:)=[];
  876. ccepx_shRalgn(rmtrials,:)=[];
  877. ccntrs=size(ccspk,1);
  878. % ccspk_shf=nan(Nshf,size(ccspk,1),size(ccspk,2)); %time-shuffle
  879. % for jj=1:Nshf %time-shuffle
  880. % for ttr=1:ccntrs %time-shuffle
  881. % isnn=find(~isnan(ccspk(ttr,:))); %time-shuffle
  882. % ccspk_shf(jj,ttr,isnn)=ccspk(ttr,isnn(randperm(length(isnn)))); %time-shuffle
  883. % %isvtps=find(vtps_ds==1); %time-shuffle
  884. % %ccspk_shf(jj,ttr,isvtps)=ccspk(ttr,isvtps(randperm(length(isvtps)))); %time-shuffle
  885. % end %time-shuffle
  886. % end %time-shuffle
  887. parfor tt=eval(selectedTimes) % delay1
  888. %for tt=eval(selectedTimes)
  889. %parfor tt=(ntce_ds(5,1):ntce_ds(5,2)) % delay2
  890. %for tt=1:Ntps_ds
  891. warning('off','all')
  892. if 1%vtps_ds(tt)==1 % discards low trials times
  893. ctspk=squeeze(ccspk(:,tt));
  894. ctepx=squeeze(ccepx(:,tt));
  895. ctspk_shLalgn=squeeze(ccspk_shLalgn(:,tt));
  896. ctspk_shRalgn=squeeze(ccspk_shRalgn(:,tt));
  897. ctlm1=fitlm(ccoff1ev,ctspk);
  898. ctlm2=fitlm(ccoff2ev,ctspk);
  899. % ctlm1=fitglm(ccoff1ev,ctspk,'linear','Distribution','poisson');
  900. % ctlm2=fitglm(ccoff2ev,ctspk,'linear','Distribution','poisson');
  901. lmELpv(cc,tt)=ctlm1.Coefficients.pValue(2);
  902. lmERpv(cc,tt)=ctlm2.Coefficients.pValue(2);
  903. lmELR2(cc,tt)=ctlm1.Rsquared.Ordinary;
  904. lmERR2(cc,tt)=ctlm2.Rsquared.Ordinary;
  905. lmELb0(cc,tt)=ctlm1.Coefficients.Estimate(1);
  906. lmERb0(cc,tt)=ctlm2.Coefficients.Estimate(1);
  907. lmELb1(cc,tt)=ctlm1.Coefficients.Estimate(2);
  908. lmERb1(cc,tt)=ctlm2.Coefficients.Estimate(2);
  909. cciso1LL=(nanmean(ccepx(:,off1time),2)<0);
  910. ccisd1LL=(nanmean(ccepx(:,del1time),2)<0);
  911. cciso2LL=(nanmean(ccepx(:,off2time),2)<0);
  912. ccisd2LL=(nanmean(ccepx(:,del2time),2)<0);
  913. %[nuL,~,~,ishiftsL]=nanmonotonicdrifts_forward_simplified(ccepx(:,fulldel1time),2,0,-1,1,1);
  914. %check1=find(~isnan(ishiftsL));
  915. %check0=find((ccisdelSL));
  916. % ccisd1allLL=(arrayfun(@(xx) all((ccepx(xx,fulldel1time(1)-1+find(~isnan(ccepx(xx,fulldel1time)))))<=0),1:size(ccepx,1)));
  917. % ccisd1allLR=(arrayfun(@(xx) all((ccepx(xx,fulldel1time(1)-1+find(~isnan(ccepx(xx,fulldel1time)))))>=0),1:size(ccepx,1)));
  918. ccisd1allLL=(arrayfun(@(xx) all((ccepx(xx,fulldel1time(41)-1+find(~isnan(ccepx(xx,fulldel1time(41:end))))))<=0),1:size(ccepx,1)));
  919. ccisd1allLR=(arrayfun(@(xx) all((ccepx(xx,fulldel1time(41)-1+find(~isnan(ccepx(xx,fulldel1time(41:end))))))>=0),1:size(ccepx,1)));
  920. %fullfig(); subplot(1,2,1); plot(fulldel1time,ccepx(ccisd1allLL,fulldel1time));
  921. % subplot(1,2,2); plot(fulldel1time,ccepx(ccisd1allLR,fulldel1time));
  922. % ccisd2allLL=(arrayfun(@(xx) all((ccepx(xx,fulldel2time(1)-1+find(~isnan(ccepx(xx,fulldel2time)))))<=0),1:size(ccepx,1)));
  923. % ccisd2allLR=(arrayfun(@(xx) all((ccepx(xx,fulldel2time(1)-1+find(~isnan(ccepx(xx,fulldel2time)))))>=0),1:size(ccepx,1)));
  924. ccisd2allLL=(arrayfun(@(xx) all((ccepx(xx,fulldel2time(41)-1+find(~isnan(ccepx(xx,fulldel2time(41:end))))))<=0),1:size(ccepx,1)));
  925. ccisd2allLR=(arrayfun(@(xx) all((ccepx(xx,fulldel2time(41)-1+find(~isnan(ccepx(xx,fulldel2time(41:end))))))>=0),1:size(ccepx,1)));
  926. %fullfig(); subplot(1,2,1); plot(fulldel2time,ccepx(ccisd2allLL,fulldel2time));
  927. % subplot(1,2,2); plot(fulldel2time,ccepx(ccisd2allLR,fulldel2time));
  928. switch selflag
  929. case 1 % OFFER1 LookL and DELAY1 LookL/R
  930. %isLL=find((cciso1LL) & (ccepx(:,tt)<0));
  931. %isLR=find((cciso1LL) & (ccepx(:,tt)>0));
  932. %isLL=find((cciso1LL) & (ccisdelSL));
  933. %isLR=find((cciso1LL) & (ccisdelSR));
  934. %isLL=find((ccisdelSL));
  935. %isLR=find((ccisdelSR));
  936. switch caseflag
  937. case {1,2}
  938. isLL=find((ccisdelSL));
  939. isLR=find((ccisdelSR));
  940. case 3
  941. isLL=find((ccisd1allLL));
  942. isLR=find((ccisd1allLR));
  943. case {4,5}
  944. isLL=find((cciso1LL) & (ccisdelSL));
  945. isLR=find((cciso1LL) & (ccisdelSR));
  946. case 6
  947. isLL=find((cciso1LL) & (ccisd1allLL)');
  948. isLR=find((cciso1LL) & (ccisd1allLR)');
  949. end
  950. case 2 % OFFER1 LookR and DELAY1 LookL/R
  951. %isLL=find((~cciso1LL) & (ccepx(:,tt)<0));
  952. %isLR=find((~cciso1LL) & (ccepx(:,tt)>0));
  953. isLL=find((~cciso1LL) & (ccisdelSL));
  954. isLR=find((~cciso1LL) & (ccisdelSR));
  955. case 3 % OFFER2 LookL and DELAY2 LookL/R
  956. %isLL=find((cciso2LL) & (ccepx(:,tt)<0));
  957. %isLR=find((cciso2LL) & (ccepx(:,tt)>0));
  958. isLL=find((cciso2LL) & (ccisdelSL));
  959. isLR=find((cciso2LL) & (ccisdelSR));
  960. case 4 % OFFER2 LookR and DELAY2 LookL/R
  961. %isLL=find((~cciso2LL) & (ccepx(:,tt)<0));
  962. %isLR=find((~cciso2LL) & (ccepx(:,tt)>0));
  963. %isLL=find((~cciso2LL) & (ccisdelSL));
  964. %isLR=find((~cciso2LL) & (ccisdelSR));
  965. %isLL=find((ccisdelSL));
  966. %isLR=find((ccisdelSR));
  967. switch caseflag
  968. case {1,2}
  969. isLL=find((ccisdelSL));
  970. isLR=find((ccisdelSR));
  971. case 3
  972. isLL=find((ccisd2allLL));
  973. isLR=find((ccisd2allLR));
  974. case {4,5}
  975. isLL=find((~cciso2LL) & (ccisdelSL));
  976. isLR=find((~cciso2LL) & (ccisdelSR));
  977. case 6
  978. isLL=find((~cciso2LL) & (ccisd2allLL)');
  979. isLR=find((~cciso2LL) & (ccisd2allLR)');
  980. end
  981. %isLL=find((~cciso2LL) & (ccisd2allLL)');
  982. %isLR=find((~cciso2LL) & (ccisd2allLR)');
  983. %isLL=find((ccisd2allLL));
  984. %isLR=find((ccisd2allLR));
  985. end
  986. %Relevant cases:
  987. % Left in offer1 and Right in delay1
  988. % Right in offer2 and Left in delay2
  989. % control cases:
  990. % Right in offer1
  991. % Left in offer2
  992. niLL=length(isLL);
  993. if (caseflag==3 || caseflag==6)
  994. ctlm1LL=fitlm(ccoff1ev(isLL),ctspk(isLL));
  995. ctlm2LL=fitlm(ccoff2ev(isLL),ctspk(isLL));
  996. else
  997. ctlm1LL=fitlm(ccoff1ev(isLL),ctspk_shLalgn(isLL));
  998. ctlm2LL=fitlm(ccoff2ev(isLL),ctspk_shLalgn(isLL));
  999. end
  1000. lmELpvLL(cc,tt)=ctlm1LL.Coefficients.pValue(2);
  1001. lmERpvLL(cc,tt)=ctlm2LL.Coefficients.pValue(2);
  1002. lmELR2LL(cc,tt)=ctlm1LL.Rsquared.Ordinary;
  1003. lmERR2LL(cc,tt)=ctlm2LL.Rsquared.Ordinary;
  1004. lmELb0LL(cc,tt)=ctlm1LL.Coefficients.Estimate(1);
  1005. lmERb0LL(cc,tt)=ctlm2LL.Coefficients.Estimate(1);
  1006. lmELb1LL(cc,tt)=ctlm1LL.Coefficients.Estimate(2);
  1007. lmERb1LL(cc,tt)=ctlm2LL.Coefficients.Estimate(2);
  1008. lmntrsLL(cc,tt)=niLL;
  1009. lmntrsLL_nn(cc,tt)=sum(~isnan(ctspk(isLL)));
  1010. lmntrsLL_nn_shLalgn(cc,tt)=sum(~isnan(ctspk_shLalgn(isLL)));
  1011. niLR=length(isLR);
  1012. if (caseflag==3 || caseflag==6)
  1013. ctlm1LR=fitlm(ccoff1ev(isLR),ctspk(isLR));
  1014. ctlm2LR=fitlm(ccoff2ev(isLR),ctspk(isLR));
  1015. else
  1016. ctlm1LR=fitlm(ccoff1ev(isLR),ctspk_shRalgn(isLR));
  1017. ctlm2LR=fitlm(ccoff2ev(isLR),ctspk_shRalgn(isLR));
  1018. end
  1019. lmELpvLR(cc,tt)=ctlm1LR.Coefficients.pValue(2);
  1020. lmERpvLR(cc,tt)=ctlm2LR.Coefficients.pValue(2);
  1021. lmELR2LR(cc,tt)=ctlm1LR.Rsquared.Ordinary;
  1022. lmERR2LR(cc,tt)=ctlm2LR.Rsquared.Ordinary;
  1023. lmELb0LR(cc,tt)=ctlm1LR.Coefficients.Estimate(1);
  1024. lmERb0LR(cc,tt)=ctlm2LR.Coefficients.Estimate(1);
  1025. lmELb1LR(cc,tt)=ctlm1LR.Coefficients.Estimate(2);
  1026. lmERb1LR(cc,tt)=ctlm2LR.Coefficients.Estimate(2);
  1027. lmntrsLR(cc,tt)=niLR;
  1028. lmntrsLR_nn(cc,tt)=sum(~isnan(ctspk(isLR)));
  1029. lmntrsLR_nn_shRalgn(cc,tt)=sum(~isnan(ctspk_shRalgn(isLR)));
  1030. for shf=1:Nshf
  1031. i1shf=randperm(ccntrs); %trial-shuffle
  1032. i2shf=randperm(ccntrs); %trial-shuffle
  1033. isshf=randperm(ccntrs); %trial-shuffle
  1034. ctlm1_shf=fitlm(ccoff1ev(i1shf),ctspk(isshf)); %trial-shuffle
  1035. ctlm2_shf=fitlm(ccoff2ev(i2shf),ctspk(isshf)); %trial-shuffle
  1036. lmELpv_shf(cc,tt,shf)=ctlm1_shf.Coefficients.pValue(2);
  1037. lmERpv_shf(cc,tt,shf)=ctlm2_shf.Coefficients.pValue(2);
  1038. lmELR2_shf(cc,tt,shf)=ctlm1_shf.Rsquared.Ordinary;
  1039. lmERR2_shf(cc,tt,shf)=ctlm2_shf.Rsquared.Ordinary;
  1040. lmELb0_shf(cc,tt,shf)=ctlm1_shf.Coefficients.Estimate(1);
  1041. lmERb0_shf(cc,tt,shf)=ctlm2_shf.Coefficients.Estimate(1);
  1042. lmELb1_shf(cc,tt,shf)=ctlm1_shf.Coefficients.Estimate(2);
  1043. lmERb1_shf(cc,tt,shf)=ctlm2_shf.Coefficients.Estimate(2);
  1044. i1LLshf=isLL(randperm(niLL)); %trial-shuffle
  1045. i2LLshf=isLL(randperm(niLL)); %trial-shuffle
  1046. isLLshf=isLL(randperm(niLL)); %trial-shuffle
  1047. if (caseflag==3 || caseflag==6)
  1048. ctlm1LL_shf=fitlm(ccoff1ev(i1LLshf),ctspk(isLLshf)); %trial-shuffle
  1049. ctlm2LL_shf=fitlm(ccoff2ev(i2LLshf),ctspk(isLLshf)); %trial-shuffle
  1050. else
  1051. ctlm1LL_shf=fitlm(ccoff1ev(i1LLshf),ctspk_shLalgn(isLLshf)); %trial-shuffle
  1052. ctlm2LL_shf=fitlm(ccoff2ev(i2LLshf),ctspk_shLalgn(isLLshf)); %trial-shuffle
  1053. end
  1054. lmELpvLL_shf(cc,tt,shf)=ctlm1LL_shf.Coefficients.pValue(2);
  1055. lmERpvLL_shf(cc,tt,shf)=ctlm2LL_shf.Coefficients.pValue(2);
  1056. lmELR2LL_shf(cc,tt,shf)=ctlm1LL_shf.Rsquared.Ordinary;
  1057. lmERR2LL_shf(cc,tt,shf)=ctlm2LL_shf.Rsquared.Ordinary;
  1058. lmELb0LL_shf(cc,tt,shf)=ctlm1LL_shf.Coefficients.Estimate(1);
  1059. lmERb0LL_shf(cc,tt,shf)=ctlm2LL_shf.Coefficients.Estimate(1);
  1060. lmELb1LL_shf(cc,tt,shf)=ctlm1LL_shf.Coefficients.Estimate(2);
  1061. lmERb1LL_shf(cc,tt,shf)=ctlm2LL_shf.Coefficients.Estimate(2);
  1062. i1LRshf=isLR(randperm(niLR)); %trial-shuffle
  1063. i2LRshf=isLR(randperm(niLR)); %trial-shuffle
  1064. isLRshf=isLR(randperm(niLR)); %trial-shuffle
  1065. if (caseflag==3 || caseflag==6)
  1066. ctlm1LR_shf=fitlm(ccoff1ev(i1LRshf),ctspk(isLRshf)); %trial-shuffle
  1067. ctlm2LR_shf=fitlm(ccoff2ev(i2LRshf),ctspk(isLRshf)); %trial-shuffle
  1068. else
  1069. ctlm1LR_shf=fitlm(ccoff1ev(i1LRshf),ctspk_shRalgn(isLRshf)); %trial-shuffle
  1070. ctlm2LR_shf=fitlm(ccoff2ev(i2LRshf),ctspk_shRalgn(isLRshf)); %trial-shuffle
  1071. end
  1072. lmELpvLR_shf(cc,tt,shf)=ctlm1LR_shf.Coefficients.pValue(2);
  1073. lmERpvLR_shf(cc,tt,shf)=ctlm2LR_shf.Coefficients.pValue(2);
  1074. lmELR2LR_shf(cc,tt,shf)=ctlm1LR_shf.Rsquared.Ordinary;
  1075. lmERR2LR_shf(cc,tt,shf)=ctlm2LR_shf.Rsquared.Ordinary;
  1076. lmELb0LR_shf(cc,tt,shf)=ctlm1LR_shf.Coefficients.Estimate(1);
  1077. lmERb0LR_shf(cc,tt,shf)=ctlm2LR_shf.Coefficients.Estimate(1);
  1078. lmELb1LR_shf(cc,tt,shf)=ctlm1LR_shf.Coefficients.Estimate(2);
  1079. lmERb1LR_shf(cc,tt,shf)=ctlm2LR_shf.Coefficients.Estimate(2);
  1080. end
  1081. end
  1082. warning('on','all')
  1083. end
  1084. disp([sprintf('%s',datetime('now','Format','HH:mm')) ' - done: ' num2str(cc) '/' num2str(Nccs) ', ' num2str(cc/Nccs.*100) '%']);
  1085. end
  1086. save([most_recent_folder 'fitlmstats_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_' date '.mat'],'lmE*','lmntr*');
  1087. else
  1088. %load(['fitlmstats_span_' num2str(Nspan) 'ms_lag_' num2str(Nlag) 'ms_13-May-2022.mat']);
  1089. end
  1090. %%
  1091. hfig=fullfig(); hfig.Position=[0 0 .5 1];
  1092. if any(caseflag==[1 2 4 5])
  1093. subplot(2,1,1);
  1094. plot(rtmax_ds,(lmntrsLL_nn_shLalgn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  1095. subplot(2,1,2);
  1096. plot(rtmax_ds,(lmntrsLR_nn_shRalgn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  1097. else
  1098. subplot(2,1,1);
  1099. plot(rtmax_ds,(lmntrsLL_nn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  1100. subplot(2,1,2);
  1101. plot(rtmax_ds,(lmntrsLR_nn(cumsum(nccs),vtps_ds==1))./repmat(ntrs',1,nansum(vtps_ds)).*100);
  1102. end
  1103. switch selflag
  1104. case 1
  1105. subplot(2,1,1);
  1106. title('Look Left Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  1107. subplot(2,1,2);
  1108. title('Look Left Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  1109. case 2
  1110. subplot(2,1,1);
  1111. title('Look Right Offer1 & Look Left Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  1112. subplot(2,1,2);
  1113. title('Look Right Offer1 & Look Right Delay1'); ylim([0 100]); ylabel('% trials'); xlabel('Delay1 time bins (10 ms)');
  1114. case 3
  1115. subplot(2,1,1);
  1116. title('Look Left Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  1117. subplot(2,1,2);
  1118. title('Look Left Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  1119. case 4
  1120. subplot(2,1,1);
  1121. title('Look Right Offer2 & Look Left Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  1122. subplot(2,1,2);
  1123. title('Look Right Offer2 & Look Right Delay2'); ylim([0 100]); ylabel('% trials'); xlabel('Delay2 time bins (10 ms)');
  1124. end
  1125. hl=legend(strsplit(sprintf('session %d-',1:8),'-'));
  1126. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_selected.png']);
  1127. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_selected.fig']);
  1128. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/frac_trials_off_del_selected.svg']);
  1129. %% Plot colors
  1130. o1col = [ 55 188 52]/255;
  1131. o2col = [ 55 131 200]/255;
  1132. o3col = [121 121 121]/255;
  1133. o1LLcol=[ 50 148 48]/255;
  1134. o2LLcol=[ 55 97 135]/255;
  1135. o3LLcol=[ 43 43 43]/255;
  1136. o1LRcol=[135 215 133]/255;
  1137. o2LRcol=[144 187 226]/255;
  1138. o3LRcol=[168 168 168]/255;
  1139. o1LLcol=[212 87 28]/255;
  1140. o1LRcol=[251 179 144]/255;
  1141. o2LLcol=[119 30 152]/255;
  1142. o2LRcol=[185 118 210]/255;
  1143. %%
  1144. lmELpvd=double(lmELpv(:,vtps_ds==1)<0.05);
  1145. lmERpvd=double(lmERpv(:,vtps_ds==1)<0.05);
  1146. lmELpvdLL=double(lmELpvLL(:,vtps_ds==1)<0.05);
  1147. lmERpvdLL=double(lmERpvLL(:,vtps_ds==1)<0.05);
  1148. lmELpvdLR=double(lmELpvLR(:,vtps_ds==1)<0.05);
  1149. lmERpvdLR=double(lmERpvLR(:,vtps_ds==1)<0.05);
  1150. lmELpvd_shf=squeeze(double(lmELpv_shf(:,vtps_ds==1,:)<0.05));
  1151. lmERpvd_shf=squeeze(double(lmERpv_shf(:,vtps_ds==1,:)<0.05));
  1152. lmELpvdLL_shf=squeeze(double(lmELpvLL_shf(:,vtps_ds==1,:)<0.05));
  1153. lmERpvdLL_shf=squeeze(double(lmERpvLL_shf(:,vtps_ds==1,:)<0.05));
  1154. lmELpvdLR_shf=squeeze(double(lmELpvLR_shf(:,vtps_ds==1,:)<0.05));
  1155. lmERpvdLR_shf=squeeze(double(lmERpvLR_shf(:,vtps_ds==1,:)<0.05));
  1156. hfig=fullfig();
  1157. subplot(3,1,1);
  1158. plotcmapdots([o1col; o2col]); hold on
  1159. runlength(nanmean(lmELpvd),squeeze(nanmean(lmELpvd_shf)),1,rtmax_ds,o1col,0.005);
  1160. runlength(nanmean(lmERpvd),squeeze(nanmean(lmERpvd_shf)),1,rtmax_ds,o2col,0.002);
  1161. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),[0 0.2],'k:'); text(sum(rtmes_ds(1:jj-1)),.21,twLabels{jj}); end
  1162. hl=legend({'E(L)','E(R)'}); ylim([0 0.2]); box(hl,'on');
  1163. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  1164. subplot(3,1,2);
  1165. plotcmapdots([o1LLcol; o1LRcol]); hold on
  1166. runlength(nanmean(lmELpvdLL),squeeze(nanmean(lmELpvdLL_shf)),1,rtmax_ds,o1LLcol,0.005);
  1167. runlength(nanmean(lmELpvdLR),squeeze(nanmean(lmELpvdLR_shf)),1,rtmax_ds,o1LRcol,0.002);
  1168. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),[0 0.2],'k:'); text(sum(rtmes_ds(1:jj-1)),.21,twLabels{jj}); end
  1169. hl=legend({'E(L), LookL','E(L), LookR'}); ylim([0 0.2]); box(hl,'on');
  1170. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  1171. subplot(3,1,3);
  1172. plotcmapdots([o2LLcol; o2LRcol]);
  1173. runlength(nanmean(lmERpvdLL),squeeze(nanmean(lmERpvdLL_shf)),1,rtmax_ds,o2LLcol,0.005);
  1174. runlength(nanmean(lmERpvdLR),squeeze(nanmean(lmERpvdLR_shf)),1,rtmax_ds,o2LRcol,0.002);
  1175. for jj=1:8; plot([1 1].*sum(rtmes_ds(1:jj)),[0 0.2],'k:'); text(sum(rtmes_ds(1:jj-1)),.21,twLabels{jj}); end
  1176. hl=legend({'E(R), LookL','E(R), LookR'}); ylim([0 0.2]); box(hl,'on');
  1177. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  1178. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv.png']);
  1179. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv.fig']);
  1180. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv.svg']);
  1181. %%
  1182. lmELpvd=double(lmELpv(:,:)<0.05);
  1183. lmERpvd=double(lmERpv(:,:)<0.05);
  1184. lmELpvdLL=double(lmELpvLL(:,:)<0.05);
  1185. lmERpvdLL=double(lmERpvLL(:,:)<0.05);
  1186. lmELpvdLR=double(lmELpvLR(:,:)<0.05);
  1187. lmERpvdLR=double(lmERpvLR(:,:)<0.05);
  1188. lmELpvd_shf=squeeze(double(lmELpv_shf(:,:,:)<0.05));
  1189. lmERpvd_shf=squeeze(double(lmERpv_shf(:,:,:)<0.05));
  1190. lmELpvdLL_shf=squeeze(double(lmELpvLL_shf(:,:,:)<0.05));
  1191. lmERpvdLL_shf=squeeze(double(lmERpvLL_shf(:,:,:)<0.05));
  1192. lmELpvdLR_shf=squeeze(double(lmELpvLR_shf(:,:,:)<0.05));
  1193. lmERpvdLR_shf=squeeze(double(lmERpvLR_shf(:,:,:)<0.05));
  1194. hfig=fullfig();
  1195. subplot(3,1,1);
  1196. plotcmapdots([o1col; o2col]);
  1197. runlength(nanmean(lmELpvd),squeeze(nanmean(lmELpvd_shf)),1,1:Ntps_ds,o1col,0.005);
  1198. runlength(nanmean(lmERpvd),squeeze(nanmean(lmERpvd_shf)),1,1:Ntps_ds,o2col,0.002);
  1199. ylim([0 0.2]); for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  1200. hl=legend({'E(L)','E(R)'}); box(hl,'on'); box off;
  1201. if selflag<=2; xlim(fulldel1time([1 end])); else; xlim(fulldel2time([1 end])); end
  1202. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  1203. subplot(3,1,2);
  1204. plotcmapdots([o1LLcol; o1LRcol]);
  1205. runlength(nanmean(lmELpvdLL),squeeze(nanmean(lmELpvdLL_shf)),1,1:Ntps_ds,o1LLcol,0.005);
  1206. runlength(nanmean(lmELpvdLR),squeeze(nanmean(lmELpvdLR_shf)),1,1:Ntps_ds,o1LRcol,0.002);
  1207. ylim([0 0.2]); for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  1208. hl=legend({'E(L), LookL','E(L), LookR'}); box(hl,'on'); box off;
  1209. if selflag<=2; xlim(fulldel1time([1 end])); else; xlim(fulldel2time([1 end])); end
  1210. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  1211. subplot(3,1,3);
  1212. plotcmapdots([o2LLcol; o2LRcol]);
  1213. runlength(nanmean(lmERpvdLL),squeeze(nanmean(lmERpvdLL_shf)),1,1:Ntps_ds,o2LLcol,0.005);
  1214. runlength(nanmean(lmERpvdLR),squeeze(nanmean(lmERpvdLR_shf)),1,1:Ntps_ds,o2LRcol,0.002);
  1215. ylim([0 0.2]); for jj=1:7; plotvline(ntce_ds(jj,1:2)); text(ntce_ds(jj,1),max(get(gca,'YLim')),twLabels{jj}); end
  1216. hl=legend({'E(R), LookL','E(R), LookR'}); box(hl,'on'); box off;
  1217. if selflag<=2; xlim(fulldel1time([1 end])); else; xlim(fulldel2time([1 end])); end
  1218. xlabel('time bins (10 ms)'); ylabel('% signif. cells');
  1219. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv_deltime.png']);
  1220. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv_deltime.fig']);
  1221. saveas(hfig,[most_recent_folder 'span' num2str(Nspan) 'ms_lag' num2str(Nlag) 'ms/sig_in_time_pv_deltime.svg']);
  1222. end
  1223. end