neuralAnalysesOfferShiftAligned.m 86 KB

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