pRF_AvgSessions_odd.m 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. function pRF_AvgSessions_odd(MONKEY)
  2. if nargin < 1
  3. MONKEY={'M01','M02'};
  4. end
  5. %% Merge median BOLD signals
  6. clc;
  7. startfld=pwd;
  8. for m=1:length(MONKEY)
  9. fprintf(['==== Processing monkey: ' MONKEY{m} ' ====\n']);
  10. cd(fullfile(SHARED_ROOT_FLD,'Raw_data','MRI','Raw_matlab','us-padded',MONKEY{m}));
  11. fls = dir('medianBOLD*');
  12. MB.medianBOLD=[]; MB.medianBOLD_inv=[];
  13. MB.nRuns=[]; MB.nRuns_inv=[];
  14. MB.stim={}; MB.stim_inv={};
  15. for f=1:2:length(fls)
  16. fprintf(['Adding ' fls(f).name '\n']);
  17. M = load(fls(f).name);
  18. MB.medianBOLD = cat(5,MB.medianBOLD,M.medianBOLD);
  19. MB.nRuns = cat(5,MB.nRuns,M.nRuns);
  20. MB.stim = M.stim;
  21. if isfield(M,'medianBOLD_inv')
  22. MB.medianBOLD_inv = cat(5,MB.medianBOLD_inv,M.medianBOLD_inv);
  23. MB.nRuns_inv = cat(5,MB.nRuns_inv,M.nRuns_inv);
  24. MB.stim_inv = M.stim_inv;
  25. end
  26. clear M
  27. end
  28. stim.norm=MB.stim;
  29. % normal mean
  30. sess_meanBOLD = nanmean(MB.medianBOLD,5);
  31. % weighted mean by number of runs
  32. sess_wmeanBOLD = nansum(MB.medianBOLD.*MB.nRuns,5)./...
  33. nansum(MB.nRuns,5);
  34. % std
  35. sess_sdBOLD = nanstd(MB.medianBOLD,1,5);
  36. %median
  37. sess_medianBOLD = nanmedian(MB.medianBOLD,5);
  38. if isfield(MB,'medianBOLD_inv')
  39. stim.inv=MB.stim_inv;
  40. % normal mean
  41. sess_meanBOLD_inv = nanmean(MB.medianBOLD_inv,5);
  42. % weighted mean by number of runs
  43. sess_wmeanBOLD_inv = nansum(MB.medianBOLD_inv.*MB.nRuns_inv,5)./...
  44. nansum(MB.nRuns_inv,5);
  45. % std
  46. sess_sdBOLD_inv = nanstd(MB.medianBOLD_inv,1,5);
  47. %median
  48. sess_medianBOLD_inv = nanmedian(MB.medianBOLD_inv,5);
  49. end
  50. % remove volumes for which stim is nan ----
  51. nostim_idx=[];
  52. for i=1:size(stim.norm,2)
  53. if isnan(stim.norm{i}(1,1))
  54. nostim_idx=[nostim_idx i]; %#ok<*AGROW>
  55. end
  56. end
  57. stim.norm(nostim_idx)=[];
  58. sess_meanBOLD(:,:,:,nostim_idx)=[];
  59. sess_wmeanBOLD(:,:,:,nostim_idx)=[];
  60. sess_medianBOLD(:,:,:,nostim_idx)=[];
  61. sess_sdBOLD(:,:,:,nostim_idx)=[];
  62. if isfield(MB,'medianBOLD_inv')
  63. nostim_idx=[];
  64. for i=1:size(stim.inv,2)
  65. if isnan(stim.inv{i}(1,1))
  66. nostim_idx=[nostim_idx i];
  67. end
  68. end
  69. stim.inv(nostim_idx)=[];
  70. sess_meanBOLD_inv(:,:,:,nostim_idx)=[];
  71. sess_wmeanBOLD_inv(:,:,:,nostim_idx)=[];
  72. sess_medianBOLD_inv(:,:,:,nostim_idx)=[];
  73. sess_sdBOLD_inv(:,:,:,nostim_idx)=[];
  74. end
  75. % ----
  76. outfld = fullfile(SHARED_ROOT_FLD,'Preprocessed_data','MRI',MONKEY{m});
  77. [~,~,~] = mkdir(outfld);
  78. save(fullfile(outfld,'AllSessions-avg-odd'),'stim','sess_meanBOLD','sess_meanBOLD_inv',...
  79. 'sess_wmeanBOLD','sess_wmeanBOLD_inv','sess_medianBOLD','sess_medianBOLD_inv',...
  80. 'sess_sdBOLD','sess_sdBOLD_inv');
  81. cd(startfld);
  82. clear MB
  83. fprintf('\n\n');
  84. end