DD_Plotting.m 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. %% define some variables
  2. filt = 2; % 1: non, 2: 0.1 Hz, 3: 10 Hz, 4: 150 Hz, 5: 300 Hz
  3. cutTime = 1; % plot only certain time window? (0: no, 1: short, 2: long)
  4. avType = 1; % plot grand average (1) or individual averages (2)
  5. fixedY = 1; % use dynamic (0) or fixed (1) y-axis?
  6. inclCtrl = 2; % plot control data? (0: no, 1: 50 %, 2: MR, 3: both controls)
  7. statsType = 2; % decide which statistics to use if control is included; 1: t-test, 2: ANOVA
  8. plotWinI = 1; % plot RMS-windows?
  9. plotRespI = 1; % plot responses?
  10. plotDifI = 0; % plot difference curves?
  11. plotMtrxI = 0; % plot all responses in a matrix?
  12. plotHmI = 0; % plot heatmap?
  13. hmDataI = 1; % choose data that should be plotted as heatmap (1: Cohens D; 2: RMS of control, only useful for 50Per dataset)
  14. plotBpI = 0; % plot boxplots?
  15. stimMark = 0; % decide how to plot the stimulus (no: 0, bar: 1)
  16. cStart = 1; % stimulus combination to start with
  17. oDisEloc = 0; % plot only DisNoAM and Eloc?
  18. saveI = 0; % save figure?
  19. % decide which set of rms-windows to plot
  20. switch filt
  21. case {1,2,3}
  22. switch cutTime
  23. case 0
  24. uWin = (1:5);
  25. boxpFigWi = 800; % width of boxplot figure
  26. case 1
  27. uWin = (4:4);
  28. boxpFigWi = 300; % width of boxplot figure
  29. case 2
  30. uWin = (4:5);
  31. boxpFigWi = 500; % width of boxplot figure
  32. end
  33. case {4,5}
  34. uWin = (1:3);
  35. boxpFigWi = 500; % width of boxplot figure
  36. end
  37. % uWin = uWin+5;
  38. switch filt
  39. case 1
  40. filtName = 'noF';
  41. y_lim = [-3.5,13];
  42. case 2
  43. filtName = '0.1F';
  44. y_lim = [-3.5,13];
  45. case 3
  46. filtName = '10F';
  47. y_lim = [-3.5,13];
  48. case 4
  49. filtName = '150F';
  50. y_lim = [-4.5,4.5];
  51. case 5
  52. filtName = '300F';
  53. y_lim = [-4,4];
  54. end
  55. % define colors and names
  56. colDev = [1,0,0]; % dev: red
  57. colStd = [0,0,1]; % std: blue
  58. col50Per = [1,0,1]; % 50 %: magenta
  59. colMR = [0,0,0]; % MR: black
  60. nameDev = 'Deviant';
  61. nameStd = 'Standard';
  62. name50Per = '50 % Control';
  63. nameMR = 'MS Control';
  64. %% load processed data
  65. switch inclCtrl
  66. case 0
  67. load('DD_statsData_noCtrl.mat') % load stats data
  68. case 1 % load 50Per data and rename important variables
  69. load('DD_avData_50Per.mat')
  70. dataAv_cell_Ctrl = dataAv_cell; % rename
  71. dataGrAv_cell_Ctrl = dataGrAv_cell;
  72. dataDifAv_cell_Ctrl = dataDifAv_cell; % rename
  73. dataDifGrAv_cell_Ctrl = dataDifGrAv_cell;
  74. dataSe_cell_Ctrl = dataSe_cell;
  75. filenames_cell_Ctrl = filenames_cell;
  76. load('DD_statsData_50Per.mat') % load stats data
  77. nameCtrl = name50Per;
  78. colCtrl = col50Per; % set control color to 50 % color
  79. case 2 % load MR data and rename important variables
  80. load('DD_avData_MR.mat')
  81. dataAv_cell_Ctrl = dataAv_cell; % rename
  82. dataGrAv_cell_Ctrl = dataGrAv_cell;
  83. dataDifAv_cell_Ctrl = dataDifAv_cell; % rename
  84. dataDifGrAv_cell_Ctrl = dataDifGrAv_cell;
  85. dataSe_cell_Ctrl = dataSe_cell;
  86. filenames_cell_Ctrl = filenames_cell;
  87. load('DD_statsData_MR.mat') % load stats data
  88. nameCtrl = nameMR;
  89. colCtrl = colMR; % set control color to MR color
  90. case 3
  91. load('DD_avData_50Per.mat')
  92. dataAv_cell_50Per = dataAv_cell; % rename
  93. dataGrAv_cell_50Per = dataGrAv_cell;
  94. dataDifAv_cell_50Per = dataDifAv_cell; % rename
  95. dataDifGrAv_cell_50Per = dataDifGrAv_cell;
  96. dataSe_cell_50Per = dataSe_cell;
  97. filenames_cell_50Per = filenames_cell;
  98. load('DD_avData_MR.mat')
  99. dataAv_cell_MR = dataAv_cell; % rename
  100. dataGrAv_cell_MR = dataGrAv_cell;
  101. dataDifAv_cell_MR = dataDifAv_cell; % rename
  102. dataDifGrAv_cell_MR = dataDifGrAv_cell;
  103. dataSe_cell_MR = dataSe_cell;
  104. filenames_cell_MR = filenames_cell;
  105. load('DD_statsData_bothCtrl.mat') % load stats data
  106. end
  107. % load Oddball data (will overwrite Ctrl variables that were not renamed)
  108. load('DD_avData_Oddball.mat')
  109. %% do some additional calculations
  110. switch zsNormI
  111. case 0
  112. ylableName = 'Voltage [µV]';
  113. case 1
  114. ylableName = 'z-norm. voltage [a.u.]';
  115. end
  116. switch cutTime
  117. case 1
  118. switch filt
  119. case {1,2,3}
  120. timeStart = -5; % starting time of the plot (relative to stim onset)
  121. timeEnd = 15; % ending time of the plot (relative to stim onset)
  122. case {4,5}
  123. timeStart = -5; % starting time of the plot (relative to stim onset)
  124. timeEnd = 15; % ending time of the plot (relative to stim onset)
  125. end
  126. case 2
  127. timeStart = -5; % starting time of the plot (relative to stim onset)
  128. timeEnd = 40; % ending time of the plot (relative to stim onset)
  129. end
  130. % some calculations for matrix- and heatmap-plotting
  131. combNameS = split(combName(cStart:end),","); % split comb names at comma
  132. if plotMtrxI==1||plotHmI==1
  133. oDisEloc = 0;
  134. cStart = 2; % skip first stimulus combination (pure tones)
  135. stimOrd = ["DisNoAM","DisAM","DisMimic","Eloc","ElocMimic"]; % define order of stimuli to plot in the matrix
  136. nStim = size(stimOrd,2);
  137. combCoord = zeros(nComb-1,2); % preallocate
  138. for c = 1:nComb-1
  139. for s = 1:2
  140. combCoord(c,s) = find(ismember(stimOrd,combNameS(c,s)));
  141. end
  142. end
  143. nTiles = 1:nStim*nStim; % number of tiles in matrix
  144. tileMtrx = reshape(nTiles,[nStim,nStim])'; % create matrix to use for indexing later
  145. end
  146. if oDisEloc==1 % plot only stim combination 7 (DisNoAM/Eloc) if oDisEloc is 1
  147. cStart = 7;
  148. nComb = 7;
  149. end
  150. %% plotting: responses
  151. if plotRespI==1
  152. switch plotMtrxI
  153. case 1
  154. figure('NumberTitle','off','Name','All Stims','Position',[0,0,2000,1300],'Renderer','painters')
  155. t = tiledlayout(nStim,nStim);
  156. end
  157. for c = cStart:nComb % run once for each stimulus combination
  158. % extract data corresponding to current stimulation-condition from
  159. % cell-arrays
  160. switch plotDifI
  161. case 0
  162. dataAv = dataAv_cell{c};
  163. dataGrAv = dataGrAv_cell{c};
  164. dataSe = dataSe_cell{c};
  165. switch inclCtrl
  166. case {1,2}
  167. dataAvCtrl = dataAv_cell_Ctrl{c};
  168. dataGrAvCtrl = dataGrAv_cell_Ctrl{c};
  169. dataSeCtrl = dataSe_cell_Ctrl{c};
  170. filenames_Ctrl = filenames_cell_Ctrl{c};
  171. bsPos = cell2mat(strfind(filenames_Ctrl,'\')); % find positions of back slashes in filename
  172. startPos = bsPos(:,end); % use last back slash position as starting point
  173. filenames_Ctrl = extractAfter(filenames_Ctrl,startPos);
  174. case 3
  175. dataAv50Per = dataAv_cell_50Per{c};
  176. dataGrAv50Per = dataGrAv_cell_50Per{c};
  177. dataSe50Per = dataSe_cell_50Per{c};
  178. filenames_50Per = filenames_cell_50Per{c};
  179. bsPos = cell2mat(strfind(filenames_50Per,'\')); % find positions of back slashes in filename
  180. startPos = bsPos(:,end); % use last back slash position as starting point
  181. filenames_50Per = extractAfter(filenames_50Per,startPos);
  182. dataAvMR = dataAv_cell_MR{c};
  183. dataGrAvMR = dataGrAv_cell_MR{c};
  184. dataSeMR = dataSe_cell_MR{c};
  185. filenames_MR = filenames_cell_MR{c};
  186. bsPos = cell2mat(strfind(filenames_MR,'\')); % find positions of back slashes in filename
  187. startPos = bsPos(:,end); % use last back slash position as starting point
  188. filenames_MR = extractAfter(filenames_MR,startPos);
  189. end
  190. case 1
  191. dataAv = dataDifAv_cell_Ctrl{c};
  192. dataGrAv = dataDifGrAv_cell_Ctrl{c};
  193. plotWinI = 0; % plot no significance windows when plotting diference curves
  194. switch inclCtrl
  195. case 0
  196. error('To plot difference curves, activate inclCtrl')
  197. case {1,2}
  198. dataAvCtrl = dataAv_cell_Ctrl{c}; % won't be plotted, only processed to keep the code simpler
  199. dataGrAvCtrl = dataGrAv_cell_Ctrl{c};
  200. filenames_Ctrl = filenames_cell_Ctrl{c};
  201. bsPos = cell2mat(strfind(filenames_Ctrl,'\')); % find positions of back slashes in filename
  202. startPos = bsPos(:,end); % use last back slash position as starting point
  203. filenames_Ctrl = extractAfter(filenames_Ctrl,startPos);
  204. case 3
  205. dataAv50Per = dataAv_cell_50Per{c}; % won't be plotted, only processed to keep the code simpler
  206. dataGrAv50Per = dataGrAv_cell_50Per{c};
  207. filenames_50Per = filenames_cell_50Per{c};
  208. bsPos = cell2mat(strfind(filenames_50Per,'\')); % find positions of back slashes in filename
  209. startPos = bsPos(:,end); % use last back slash position as starting point
  210. filenames_50Per = extractAfter(filenames_50Per,startPos);
  211. dataAvMR = dataAv_cell_MR{c}; % won't be plotted, only processed to keep the code simpler
  212. dataGrAvMR = dataGrAv_cell_MR{c};
  213. filenames_MR = filenames_cell_MR{c};
  214. bsPos = cell2mat(strfind(filenames_MR,'\')); % find positions of back slashes in filename
  215. startPos = bsPos(:,end); % use last back slash position as starting point
  216. filenames_MR = extractAfter(filenames_MR,startPos);
  217. end
  218. end
  219. filenames = filenames_cell{c};
  220. recID = recID_cell{c};
  221. bsPos = cell2mat(strfind(filenames,'\')); % find positions of back slashes in filename
  222. startPos = bsPos(:,end); % use last back slash position as starting point
  223. filenames = extractAfter(filenames,startPos);
  224. timetr = round(timetr_cell{c}*1000,4);
  225. stimDur = stimDur_cell{c}(1)*1000;
  226. stimDelay = stimDelay_cell{c}(1)*1000;
  227. stimWin = [stimDelay,stimDelay+stimDur];
  228. nFiles = nFiles_cell{c};
  229. fsDwn = fsDwn_cell{c};
  230. % process timetrace
  231. switch cutTime
  232. case 0
  233. timeWin = floor([timetr(1),timetr(end)]); % data in this window will be plotted (relative to recording onset)
  234. timeStart = timeWin(1)-(stimDelay);
  235. timeEnd = timeWin(2)-(stimDelay);
  236. timeCut = (1:size(timetr,2));
  237. case {1,2}
  238. timeWin = [round((stimDelay)+timeStart,4),...
  239. round((stimDelay)+timeEnd,4)]; % data in this window will be plotted (relative to recording onset)
  240. timeCut = round(timeWin(1)/1000*fsDwn:timeWin(2)/1000*fsDwn);
  241. end
  242. % subdivide responses for simplicity
  243. ADevAv = dataAv{1};
  244. AStdAv = dataAv{2};
  245. BDevAv = dataAv{3};
  246. BStdAv = dataAv{4};
  247. ADevGrAv = dataGrAv{1};
  248. AStdGrAv = dataGrAv{2};
  249. BDevGrAv = dataGrAv{3};
  250. BStdGrAv = dataGrAv{4};
  251. ADevSe = dataSe{1};
  252. AStdSe = dataSe{2};
  253. BDevSe = dataSe{3};
  254. BStdSe = dataSe{4};
  255. switch inclCtrl
  256. case {1,2}
  257. AAvCtrl = dataAvCtrl{1};
  258. BAvCtrl = dataAvCtrl{2};
  259. AGrAvCtrl = dataGrAvCtrl{1};
  260. BGrAvCtrl = dataGrAvCtrl{2};
  261. ASeCtrl = dataSeCtrl{1};
  262. BSeCtrl = dataSeCtrl{2};
  263. case 3
  264. AAv50Per = dataAv50Per{1};
  265. BAv50Per = dataAv50Per{2};
  266. AGrAv50Per = dataGrAv50Per{1};
  267. BGrAv50Per = dataGrAv50Per{2};
  268. ASe50Per = dataSe50Per{1};
  269. BSe50Per = dataSe50Per{2};
  270. AAvMR = dataAvMR{1};
  271. BAvMR = dataAvMR{2};
  272. AGrAvMR = dataGrAvMR{1};
  273. BGrAvMR = dataGrAvMR{2};
  274. ASeMR = dataSeMR{1};
  275. BSeMR = dataSeMR{2};
  276. end
  277. % plot single channel
  278. for s = 1:2 % once for A, once for B
  279. switch s
  280. case 1
  281. grAvStd = AStdGrAv;
  282. grAvDev = ADevGrAv;
  283. avStd = AStdAv;
  284. avDev = ADevAv;
  285. seStd = AStdSe;
  286. seDev = ADevSe;
  287. stimName = 'A';
  288. switch inclCtrl
  289. case {1,2}
  290. grAvCtrl = AGrAvCtrl;
  291. avCtrl = AAvCtrl;
  292. seCtrl = ASeCtrl;
  293. case 3
  294. grAv50Per = AGrAv50Per;
  295. av50Per = AAv50Per;
  296. se50Per = ASe50Per;
  297. grAvMR = AGrAvMR;
  298. avMR = AAvMR;
  299. seMR = ASeMR;
  300. end
  301. case 2
  302. grAvStd = BStdGrAv;
  303. grAvDev = BDevGrAv;
  304. avStd = BStdAv;
  305. avDev = BDevAv;
  306. seStd = BStdSe;
  307. seDev = BDevSe;
  308. stimName = 'B';
  309. switch inclCtrl
  310. case {1,2}
  311. grAvCtrl = BGrAvCtrl;
  312. avCtrl = BAvCtrl;
  313. seCtrl = BSeCtrl;
  314. case 3
  315. grAv50Per = BGrAv50Per;
  316. av50Per = BAv50Per;
  317. se50Per = BSe50Per;
  318. grAvMR = BGrAvMR;
  319. avMR = BAvMR;
  320. seMR = BSeMR;
  321. end
  322. end
  323. switch plotMtrxI
  324. case 0
  325. figure('NumberTitle','off','Name',[combName{c},'_',stimName],'Position',[0,0,1000,600])
  326. title(combNameS(c,s))
  327. case 1
  328. switch s % mirror coordinats with s
  329. case 1
  330. nexttile(tileMtrx(combCoord(c-1,2),combCoord(c-1,1)))
  331. case 2
  332. nexttile(tileMtrx(combCoord(c-1,1),combCoord(c-1,2)))
  333. end
  334. end
  335. switch avType
  336. case 1 % grand averages
  337. hold on
  338. switch inclCtrl
  339. case {1,2}
  340. switch plotDifI
  341. case 0 % plot control response only when difference curve is deactivated
  342. % plot standard error
  343. seHiCtrl = grAvCtrl(timeCut,filt)+seCtrl(timeCut,filt);
  344. seLoCtrl = grAvCtrl(timeCut,filt)-seCtrl(timeCut,filt);
  345. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  346. seY = [seHiCtrl',fliplr(seLoCtrl')];
  347. patch(seX,seY,colCtrl,'FaceAlpha',0.2,'EdgeColor','none')
  348. % plot data
  349. plotCtrl = plot(timetr(timeCut),grAvCtrl(timeCut,filt),'color',colCtrl,'Linewidth',2);
  350. end
  351. case 3
  352. switch plotDifI
  353. case 0 % plot control response only when difference curve is deactivated
  354. % plot standard error
  355. seHi50Per = grAv50Per(timeCut,filt)+se50Per(timeCut,filt);
  356. seLo50Per = grAv50Per(timeCut,filt)-se50Per(timeCut,filt);
  357. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  358. seY = [seHi50Per',fliplr(seLo50Per')];
  359. patch(seX,seY,col50Per,'FaceAlpha',0.2,'EdgeColor','none')
  360. % plot data
  361. plot50Per = plot(timetr(timeCut),grAv50Per(timeCut,filt),'color',col50Per,'Linewidth',2);
  362. % plot standard error
  363. seHiMR = grAvMR(timeCut,filt)+seMR(timeCut,filt);
  364. seLoMR = grAvMR(timeCut,filt)-seMR(timeCut,filt);
  365. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  366. seY = [seHiMR',fliplr(seLoMR')];
  367. patch(seX,seY,colMR,'FaceAlpha',0.2,'EdgeColor','none')
  368. % plot data
  369. plotMR = plot(timetr(timeCut),grAvMR(timeCut,filt),'color',colMR,'Linewidth',2);
  370. end
  371. end
  372. % plot standard error
  373. seHiDev = grAvDev(timeCut,filt)+seDev(timeCut,filt);
  374. seLoDev = grAvDev(timeCut,filt)-seDev(timeCut,filt);
  375. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  376. seY = [seHiDev',fliplr(seLoDev')];
  377. patch(seX,seY,colDev,'FaceAlpha',0.2,'EdgeColor','none')
  378. % plot data
  379. plotDev = plot(timetr(timeCut),grAvDev(timeCut,filt),'color',colDev,'Linewidth',2);
  380. % plot standard error
  381. seHiStd = grAvStd(timeCut,filt)+seStd(timeCut,filt);
  382. seLoStd = grAvStd(timeCut,filt)-seStd(timeCut,filt);
  383. seX = [timetr(timeCut),fliplr(timetr(timeCut))];
  384. seY = [seHiStd',fliplr(seLoStd')];
  385. patch(seX,seY,colStd,'FaceAlpha',0.2,'EdgeColor','none')
  386. % plot data
  387. plotStd = plot(timetr(timeCut),grAvStd(timeCut,filt),'color',colStd,'Linewidth',2);
  388. xticks(timeWin(1):5:timeWin(2))
  389. set(gca,'XTickLabel',timeStart:5:timeEnd)
  390. switch stimMark
  391. case 1 % plot bar
  392. y_dist = y_lim(2)-y_lim(1);
  393. y_min = y_lim(1)+y_dist*0.05;
  394. x_stim = [stimWin(1);stimWin(2);stimWin(2);stimWin(1)];
  395. y_stim = [y_min+y_dist*0.05;y_min+y_dist*0.05;y_min+y_dist*0.07;y_min+y_dist*0.07];
  396. patch('XData',x_stim,'YData',y_stim,'EdgeColor','Black','EdgeAlpha',1,'FaceColor','Black','FaceAlpha',1)
  397. end
  398. switch plotMtrxI
  399. case 0
  400. xlabel('Time [ms]','FontWeight','bold','FontSize',20)
  401. ylabel(ylableName,'FontWeight','bold','FontSize',20)
  402. switch inclCtrl
  403. case 0
  404. legend([plotDev,plotStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  405. case {1,2}
  406. switch plotDifI
  407. case 0
  408. legend([plotDev,plotStd,plotCtrl],nameDev,nameStd,nameCtrl,'Location','northwest','AutoUpdate','off')
  409. case 1
  410. legend([plotDev,plotStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  411. end
  412. case 3
  413. switch plotDifI
  414. case 0
  415. legend([plotDev,plotStd,plot50Per,plotMR],nameDev,nameStd,name50Per,nameMR,'Location','northwest','AutoUpdate','off')
  416. case 1
  417. legend([plotDev,plotStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  418. end
  419. end
  420. case 1
  421. xlabel(t,'Time [ms]','FontWeight','bold','FontSize',20)
  422. ylabel(t,ylableName,'FontWeight','bold','FontSize',20)
  423. end
  424. set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
  425. switch plotWinI
  426. case 1
  427. x_min = timetr(winAll(:,1));
  428. x_max = timetr(winAll(:,2));
  429. x = [x_min;x_max;x_max;x_min];
  430. switch fixedY
  431. case 0
  432. y_limAuto = ylim;
  433. y_min = y_limAuto(1);
  434. y_max = y_limAuto(2);
  435. case 1
  436. y_min = y_lim(1);
  437. y_max = y_lim(2);
  438. end
  439. y_temp = [y_min;y_min;y_max;y_max];
  440. y = repmat(y_temp,1,uWin(end));
  441. for w = uWin
  442. switch inclCtrl
  443. case 0
  444. statsV = pV(c,s,filt,w);
  445. case {1,2,3}
  446. switch statsType
  447. case 1 % use t-test statistics
  448. statsV = pV(c,s,filt,w);
  449. case 2 % use ANOVA statistics
  450. statsV = multcompV{c,s,filt,w}.pValue(1); % extract pValue for comparison between dev and std condition
  451. end
  452. end
  453. if statsV<0.05
  454. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','black','FaceAlpha',.2,'Linewidth',2);
  455. else
  456. sigWin = patch('XData',x(:,w),'YData',y(:,w),'EdgeColor','black','EdgeAlpha',1,'FaceColor','none','Linewidth',2);
  457. end
  458. uistack(sigWin,'bottom')
  459. end
  460. end
  461. xlim([timeWin(1),timeWin(2)])
  462. if fixedY==1
  463. ylim(y_lim)
  464. end
  465. case 2 % individual averages
  466. for f = 1:nFiles
  467. figure ('NumberTitle','off','Name',[combName{c},'_',stimName,'_',convertStringsToChars(recID(f))],'Position',[0,0,1000,500])
  468. hold on
  469. switch inclCtrl
  470. case {1,2}
  471. switch plotDifI
  472. case 0 % plot control response only when difference curve is deactivated
  473. plotCtrl = plot(timetr(timeCut),avCtrl(timeCut,f,filt),'color',colCtrl,'Linewidth',2);
  474. end
  475. case 3
  476. switch plotDifI
  477. case 0 % plot control response only when difference curve is deactivated
  478. plot50Per = plot(timetr(timeCut),av50Per(timeCut,f,filt),'color',col50Per,'Linewidth',2);
  479. plotMR = plot(timetr(timeCut),avMR(timeCut,f,filt),'color',colMR,'Linewidth',2);
  480. end
  481. end
  482. plotStd = plot(timetr(timeCut),avStd(timeCut,f,filt),'color',colStd,'Linewidth',2);
  483. plotDev = plot(timetr(timeCut),avDev(timeCut,f,filt),'color',colDev,'Linewidth',2);
  484. xticks(timeWin(1):5:timeWin(2))
  485. set(gca,'XTickLabel',timeStart:5:timeEnd)
  486. switch stimMark
  487. case 1 % plot bar
  488. y_dist = y_lim(2)-y_lim(1);
  489. y_min = y_lim(1)+y_dist*0.05;
  490. x_stim = [stimWin(1);stimWin(2);stimWin(2);stimWin(1)];
  491. y_stim = [y_min+y_dist*0.05;y_min+y_dist*0.05;y_min+y_dist*0.07;y_min+y_dist*0.07];
  492. patch('XData',x_stim,'YData',y_stim,'EdgeColor','Black','EdgeAlpha',1,'FaceColor','Black','FaceAlpha',1)
  493. end
  494. xlabel('Time [ms]','FontWeight','bold','FontSize',20)
  495. ylabel(ylableName,'FontWeight','bold','FontSize',20)
  496. set(gca,'FontSize',20,'Linewidth',2,'FontName','Arial')
  497. xlim([timeWin(1),timeWin(2)])
  498. if fixedY==1
  499. ylim(y_lim)
  500. end
  501. end
  502. end
  503. if saveI==1
  504. switch plotMtrxI
  505. case 0
  506. saveas(gcf,[combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.jpg'])
  507. saveas(gcf,[combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.svg'])
  508. end
  509. end
  510. end
  511. end
  512. if saveI==1
  513. switch plotMtrxI
  514. case 1
  515. saveas(gcf,['Matrix_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.jpg'])
  516. saveas(gcf,['Matrix_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.svg'])
  517. end
  518. end
  519. end
  520. %% plotting: data-heatmap
  521. if plotHmI==1
  522. % do some prior calculations
  523. rgb1 = [(0:0.01:1),ones(1,101)]';
  524. rgb2 = [(0:0.01:1),(1:-0.01:0)]';
  525. rgb3 = [ones(1,101),(1:-0.01:0)]';
  526. cMap = [rgb1,rgb2,rgb3];
  527. % create matrix containing the data of interest
  528. hmMtrx = NaN(nStim,nStim);
  529. for c = cStart:nComb
  530. for s = 1:2
  531. for w = uWin
  532. switch hmDataI
  533. case 1
  534. data = round(cohensD_V(c,s,filt,w,1),2); % Cohen's D of comparison between dev and std responses
  535. case 2
  536. data = round(rmsGrAv{c}(s,3,filt,w),2); % grand average RMS values of control response
  537. end
  538. switch s % mirror coordinats with s
  539. case 1
  540. hmMtrx(tileMtrx(combCoord(c-1,1),combCoord(c-1,2))) = data; % ATTENTION: coordinates change with s in the opposite way as when creating a tiled layout because matrix is filled up from top to bottom while tiled layout is filled from left to right
  541. case 2
  542. hmMtrx(tileMtrx(combCoord(c-1,2),combCoord(c-1,1))) = data;
  543. end
  544. end
  545. end
  546. end
  547. % create heatmap
  548. xvalues = stimOrd;
  549. yvalue = stimOrd;
  550. figure('NumberTitle','off','Name','Heatmap','Position',[0,0,1450,1300],'Renderer','painters')
  551. h = heatmap(xvalues,yvalue,hmMtrx);
  552. % do calculations for heatmap
  553. cmap = colormap(h);
  554. sCmap = size(cmap);
  555. h.Title = 'Cohens D';
  556. h.XLabel = 'Active Stimulus';
  557. h.YLabel = 'Modulatory Stimulus';
  558. h.MissingDataColor = [0.7,0.7,0.7];
  559. lims = clim;
  560. hmMax = max(abs(hmMtrx),[],'all');
  561. switch hmDataI
  562. case 1
  563. hmMin = -hmMax;
  564. h.Colormap = cMap;
  565. case 2
  566. hmMin = 0;
  567. h.Colormap = summer;
  568. end
  569. clim([hmMin,hmMax])
  570. set(gca,'FontSize',20,'FontName','Arial')
  571. if saveI==1
  572. saveas(gcf,['Heatmap_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.jpg'])
  573. saveas(gcf,['Heatmap_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.svg'])
  574. end
  575. end
  576. %% plotting: boxplots
  577. if plotBpI==1
  578. switch plotMtrxI
  579. case 1
  580. figure('NumberTitle','off','Name','Boxpl_All Stims','Position',[0,0,1500,1300],'Renderer','painters')
  581. t = tiledlayout(nStim,nStim);
  582. title(t,'RMS','FontWeight','bold','FontSize',25)
  583. end
  584. switch inclCtrl
  585. case 0
  586. xDev = [1,4,7,10,13];
  587. xStd = [2,5,8,11,14];
  588. sig_groups = {[1,2],[4,5],[7,8],[10,11],[13,14]};
  589. case {1,2}
  590. xDev = [1,5,9,13,17];
  591. xStd = [2,6,10,14,18];
  592. xCtrl = [3,7,11,15,19];
  593. sig_groups1 = {[1,2],[5,6],[9,10],[13,14],[17,18]}; % dev vs. std
  594. sig_groups2 = {[1,3],[5,7],[9,11],[13,15],[17,19]}; % dev vs. ctrl
  595. sig_groups3 = {[2,3],[6,7],[10,11],[14,15],[18,19]}; % std vs. ctrl
  596. case 3
  597. xDev = [1,6,11,16,21];
  598. xStd = [2,7,12,17,22];
  599. x50Per = [3,8,13,18,23];
  600. xMR = [4,9,14,19,24];
  601. sig_groups1 = {[1,2],[6,7],[11,12],[16,17],[21,22]}; % dev vs. std
  602. sig_groups2 = {[1,3],[6,8],[11,13],[16,18],[21,23]}; % dev vs. 50Per
  603. sig_groups3 = {[1,4],[6,9],[11,14],[16,19],[21,24]}; % dev vs. MR
  604. sig_groups4 = {[2,3],[7,8],[12,13],[17,18],[22,23]}; % 50Per vs. std
  605. sig_groups5 = {[2,4],[7,9],[12,14],[17,19],[22,24]}; % MR vs. std
  606. sig_groups6 = {[3,4],[8,9],[13,14],[18,19],[23,24]}; % MR vs. 50Per
  607. end
  608. for c = cStart:nComb % run once for each stimulus combination
  609. for s = 1:2 % once for A, once for B
  610. switch s
  611. case 1
  612. stimName = 'A';
  613. case 2
  614. stimName = 'B';
  615. end
  616. rmsMin = floor(min(rmsV{c}(:,s,:,filt,:),[],'all')); % identify minimum RMS value for y-limit
  617. rmsMax = ceil(max(rmsV{c}(:,s,:,filt,:),[],'all')); % identify maximum RMS value for y-limit
  618. switch plotMtrxI
  619. case 0
  620. figure('NumberTitle','off','Name',['Boxpl_',combName{c},'_',stimName],'Position',[0,0,boxpFigWi,400])
  621. title('RMS')
  622. case 1
  623. switch s % mirror coordinats with s
  624. case 1
  625. nexttile(tileMtrx(combCoord(c-1,2),combCoord(c-1,1)))
  626. case 2
  627. nexttile(tileMtrx(combCoord(c-1,1),combCoord(c-1,2)))
  628. end
  629. end
  630. ylim([rmsMin-0.5,rmsMax+1])
  631. for w = uWin
  632. hold on
  633. boxDev = boxchart(xDev(w)*ones(size(rmsV{c}(:,s,1,filt,w))),rmsV{c}(:,s,1,filt,w),'BoxFaceColor',colDev,'MarkerColor',colDev,'Linewidth',2);
  634. boxStd = boxchart(xStd(w)*ones(size(rmsV{c}(:,s,2,filt,w))),rmsV{c}(:,s,2,filt,w),'BoxFaceColor',colStd,'MarkerColor',colStd,'Linewidth',2);
  635. % switch inclCtrl
  636. % case 0
  637. % H = sigstar(sig_groups{w},pV(c,s,filt,w),cohensD_V(c,s,filt,w,1));
  638. % case {1,2}
  639. % boxCtrl = boxchart(xCtrl(w)*ones(size(rmsV{c}(:,s,3,filt,w))),rmsV{c}(:,s,3,filt,w),'BoxFaceColor',colCtrl,'MarkerColor',colCtrl,'Linewidth',2);
  640. % switch statsType
  641. % case 1
  642. % H = sigstar(sig_groups1{w},pV(c,s,filt,w),cohensD_V(c,s,filt,w,1));
  643. % case 2
  644. % statsV = multcompV{c,s,filt,w}.pValue([1,2,4]);
  645. % eS = zeros(3,1);
  646. % for cmp = 1:3
  647. % eS(cmp) = cohensD_V(c,s,filt,w,cmp);
  648. % end
  649. % H = sigstar({sig_groups1{w},sig_groups2{w},sig_groups3{w}},statsV,eS);
  650. % end
  651. % case 3
  652. % box50Per = boxchart(x50Per(w)*ones(size(rmsV{c}(:,s,3,filt,w))),rmsV{c}(:,s,3,filt,w),'BoxFaceColor',col50Per,'MarkerColor',col50Per,'Linewidth',2);
  653. % boxMR = boxchart(xMR(w)*ones(size(rmsV{c}(:,s,4,filt,w))),rmsV{c}(:,s,4,filt,w),'BoxFaceColor',colMR,'MarkerColor',colMR,'Linewidth',2);
  654. % switch statsType
  655. % case 1
  656. % H = sigstar(sig_groups1{w},pV(c,s,filt,w),cohensD_V(c,s,filt,w,1));
  657. % case 2
  658. % statsV = multcompV{c,s,filt,w}.pValue([1,2,3,5,6,9]);
  659. % eS = zeros(6,1);
  660. % for cmp = 1:6
  661. % eS(cmp) = cohensD_V(c,s,filt,w,cmp);
  662. % end
  663. % H = sigstar({sig_groups1{w},sig_groups2{w},sig_groups3{w},sig_groups4{w},sig_groups5{w},sig_groups6{w}},statsV,eS);
  664. % end
  665. % end
  666. set(H(:,2),'FontSize',25,'FontName','Arial')
  667. end
  668. switch inclCtrl
  669. case 0
  670. xlim([xDev(uWin(1))-1,xStd(uWin(end))+1])
  671. xticks((xDev(uWin)+xStd(uWin))/2)
  672. % legend([boxDev,boxStd],nameDev,nameStd,'Location','northwest','AutoUpdate','off')
  673. case {1,2}
  674. xlim([xDev(uWin(1))-1,xCtrl(uWin(end))+1])
  675. xticks(xStd(uWin))
  676. % legend([boxDev,boxStd,boxCtrl],nameDev,nameStd,nameCtrl,'Location','northwest','AutoUpdate','off')
  677. case 3
  678. xlim([xDev(uWin(1))-1,xMR(uWin(end))+1])
  679. xticks((xStd(uWin)+x50Per(uWin))/2)
  680. % legend([boxDev,boxStd,box50Per,boxMR],nameDev,nameStd,name50Per,nameMR,'Location','northwest','AutoUpdate','off')
  681. end
  682. switch plotMtrxI
  683. case 0
  684. ylabel(ylableName,'FontWeight','bold','FontSize',20)
  685. xticklabels(winTxt(uWin))
  686. case 1
  687. ylabel(t,ylableName,'FontWeight','bold','FontSize',20)
  688. xticks([])
  689. ylim([0,15])
  690. end
  691. set(gca,'FontSize',25,'Linewidth',2,'FontName','Arial')
  692. if saveI==1
  693. switch plotMtrxI
  694. case 0
  695. saveas(gcf,['Boxp_',combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.jpg'])
  696. saveas(gcf,['Boxp_',combName{c},'_',stimName,'_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.svg'])
  697. end
  698. end
  699. end
  700. end
  701. if saveI==1
  702. switch plotMtrxI
  703. case 1
  704. saveas(gcf,['Boxpl_Matrix_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.jpg'])
  705. saveas(gcf,['Boxpl_Matrix_',filtName,'_cutTime',num2str(cutTime),'_ctrl',num2str(inclCtrl),'.svg'])
  706. end
  707. end
  708. end