e1_taskPLS_memory_erp_trace.m 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. currentFile = mfilename('fullpath');
  2. [pathstr,~,~] = fileparts(currentFile);
  3. cd(fullfile(pathstr,'..'))
  4. rootpath = pwd;
  5. pn.data_eeg = fullfile(rootpath, '..', 'eegmp_preproc', 'data', 'outputs', 'eeg');
  6. pn.data_erp = fullfile(rootpath, 'data', 'erp');
  7. pn.data_erf = fullfile(rootpath, 'data', 'erf');
  8. pn.tools = fullfile(rootpath, 'tools');
  9. addpath(fullfile(rootpath, '..', 'eegmp_preproc', 'tools', 'fieldtrip')); ft_defaults
  10. addpath(fullfile(pn.tools, 'BrewerMap'));
  11. addpath(fullfile(pn.tools, 'shadedErrorBar'));
  12. %% load erp
  13. for ind_id = 1:33
  14. id = sprintf('sub-%03d', ind_id); disp(id)
  15. load(fullfile(pn.data_erp, [id,'_erp_bl.mat']));
  16. for ind_option = 2:3
  17. if ind_id == 1
  18. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}) = erp_bl.subsequent_memory{ind_option};
  19. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}) = ...
  20. rmfield(erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}), {'avg', 'var', 'dof'});
  21. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}).dimord = 'sub_chan_time';
  22. end
  23. erpgroup.subsequent_memory.(conds.subsequent_memory{ind_option}).avg(ind_id,:,:) = erp_bl.subsequent_memory{ind_option}.avg;
  24. end
  25. end
  26. time = erpgroup.subsequent_memory.subsequent_remembered.time;
  27. elec = erpgroup.subsequent_memory.subsequent_remembered.elec;
  28. channels = erpgroup.subsequent_memory.subsequent_remembered.label;
  29. mergeddata = cat(4, erpgroup.subsequent_memory.subsequent_forgotten.avg, ...
  30. erpgroup.subsequent_memory.subsequent_remembered.avg);
  31. smoothdur = 10; % 5 = 10 ms
  32. %% visualize differences
  33. idx_chans = [44,14,9,15];
  34. % avg across channels and conditions
  35. condAvg = squeeze(nanmean(nanmean(mergeddata(:,idx_chans,:,1:2),2),4));
  36. h = figure('units','centimeters','position',[0 0 10 8]);
  37. cla; hold on;
  38. % new value = old value ? subject average + grand average
  39. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,1),2));
  40. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  41. standError = nanstd(curData,1)./sqrt(size(curData,1));
  42. l1 = shadedErrorBar(time,smoothts(nanmean(curData,1),'b',smoothdur),smoothts(standError,'b',smoothdur),...
  43. 'lineprops', {'color', 'k','linewidth', 2}, 'patchSaturation', .1);
  44. curData = squeeze(nanmean(mergeddata(:,idx_chans,:,2),2));
  45. curData = curData-condAvg+repmat(nanmean(condAvg,1),size(condAvg,1),1);
  46. standError = nanstd(curData,1)./sqrt(size(curData,1));
  47. l2 = shadedErrorBar(time,smoothts(nanmean(curData,1),'b',smoothdur),smoothts(standError,'b',smoothdur),...
  48. 'lineprops', {'color', 'r','linewidth', 2}, 'patchSaturation', .1);
  49. % ax = gca; ax.YDir = 'reverse';
  50. legend([l1.mainLine, l2.mainLine],{'forgotten', 'remembered'}, ...
  51. 'location', 'southwest'); legend('boxoff')
  52. xlabel('Time (s) from stim onset')
  53. xlim([-.25 1.9]); %ylim(YLim)
  54. ylabel({'ERP';'(microVolts)'});
  55. xlabel({'Time (s)'});
  56. set(findall(gcf,'-property','FontSize'),'FontSize',14)