ck_BasicProc_AllFits_cv1.m 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008
  1. function ck_BasicProc_AllFits_cv1
  2. % this script will do some basic processing
  3. %%
  4. % clear all;
  5. clc;
  6. CVMODE='cv1';
  7. %% LOAD DATA ==============================================================
  8. homefld = pwd;
  9. cd ../../../
  10. SHARED_ROOT_FLD = pwd;
  11. cd(homefld)
  12. fitres_path = fullfile(SHARED_ROOT_FLD,'FitResults');
  13. fprintf('==============================\n')
  14. fprintf('Loading data...');
  15. load(fullfile(fitres_path,'MULTIMODAL',...
  16. ['AllFits_' CVMODE]),'R_MRI','R_EPHYS','D99');
  17. fprintf('DONE\n')
  18. fprintf('==============================\n')
  19. output_path = fullfile(SHARED_ROOT_FLD,'FitResults',...
  20. 'MULTIMODAL', CVMODE);
  21. [~,~] = mkdir(output_path);
  22. %% MRI --------------------------------------------------------------------
  23. fprintf('MRI data ---------------------\n');
  24. for r = 1:length(R_MRI) % animals
  25. for m = 1:length(R_MRI(r).model) % model fits
  26. fprintf(['Processing MODEL ' R_MRI(r).model(m).prfmodel '\n']);
  27. % convert pixels to degrees
  28. R_MRI(r).model(m).rfs = R_MRI(r).model(m).rfs./10; %#ok<*SAGROW>
  29. R_MRI(r).model(m).ecc = R_MRI(r).model(m).ecc./10;
  30. R_MRI(r).model(m).fwhm = R_MRI(r).model(m).fwhm./10;
  31. F={'rfs','gain','R2','fwhm','sdratio','normamp','expt'};
  32. % avg some values
  33. for f=1:length(F)
  34. if ~isempty(R_MRI(r).model(m).(F{f}))
  35. R_MRI(r).model(m).avg.(F{f}) = mean(R_MRI(r).model(m).(F{f}),1);
  36. end
  37. end
  38. % XY
  39. R_MRI(r).model(m).X = R_MRI(r).model(m).ecc.*cosd(R_MRI(r).model(m).ang);
  40. R_MRI(r).model(m).Y = R_MRI(r).model(m).ecc.*sind(R_MRI(r).model(m).ang);
  41. % avg XY
  42. R_MRI(r).model(m).avg.X=mean(R_MRI(r).model(m).X,1);
  43. R_MRI(r).model(m).avg.Y=mean(R_MRI(r).model(m).Y,1);
  44. R_MRI(r).model(m).avg.ecc=sqrt( ...
  45. R_MRI(r).model(m).avg.X.^2 + R_MRI(r).model(m).avg.Y.^2);
  46. % avg angle
  47. rawang = atand(R_MRI(r).model(m).avg.Y./R_MRI(r).model(m).avg.X);
  48. rawang(R_MRI(r).model(m).avg.X<0 & R_MRI(r).model(m).avg.Y<0) = ...
  49. rawang(R_MRI(r).model(m).avg.X<0 & R_MRI(r).model(m).avg.Y<0)-180;
  50. rawang(R_MRI(r).model(m).avg.X<0 & R_MRI(r).model(m).avg.Y>=0) = ...
  51. rawang(R_MRI(r).model(m).avg.X<0 & R_MRI(r).model(m).avg.Y>=0)+180;
  52. R_MRI(r).model(m).avg.ang = rawang;
  53. % dXY
  54. R_MRI(r).model(m).diff.XY = sqrt(...
  55. diff(R_MRI(r).model(m).X,1,1).^2 + ...
  56. diff(R_MRI(r).model(m).Y,1,1).^2);
  57. % dRFS
  58. R_MRI(r).model(m).diff.rfs = diff(R_MRI(r).model(m).rfs,1,1);
  59. % get maximum R2 version of some values
  60. [R_MRI(r).model(m).max.R2, R_MRI(r).model(m).max.R2_idx] = ...
  61. max(R_MRI(r).model(m).R2,[],1);
  62. R_MRI(r).model(m).max.R2_idx = ...
  63. [R_MRI(r).model(m).max.R2_idx==1; R_MRI(r).model(m).max.R2_idx==2];
  64. F={'rfs','gain','ecc','ang','fwhm','sdratio','normamp','expt'};
  65. for f=1:length(F)
  66. if ~isempty(R_MRI(r).model(m).(F{f}))
  67. R_MRI(r).model(m).max.(F{f}) = ...
  68. R_MRI(r).model(m).(F{f})(R_MRI(r).model(m).max.R2_idx)';
  69. end
  70. end
  71. R_MRI(r).model(m).max.X = R_MRI(r).model(m).X(R_MRI(r).model(m).max.R2_idx)';
  72. R_MRI(r).model(m).max.Y = R_MRI(r).model(m).Y(R_MRI(r).model(m).max.R2_idx)';
  73. end
  74. % ROIs ----
  75. R_MRI(r).Brainmask = R_MRI(r).BRAIN>0;
  76. R_MRI(r).D99 = D99;
  77. end
  78. %% EPHYS ------------------------------------------------------------------
  79. fprintf('Ephys data ---------------------\n');
  80. for r = 1:length(R_EPHYS) % animals
  81. for m = 1:length(R_EPHYS(r).model) % model fits
  82. fprintf(['Processing MODEL ' R_EPHYS(r).model(m).prfmodel '\n']);
  83. if ~strcmp(R_EPHYS(r).model(m).prfmodel,'classicRF')
  84. %% MUA --------------------------------------------------------
  85. fprintf('MUA ');
  86. for i = 1:8 % all instances
  87. % make name consistent with MRI
  88. R_EPHYS(r).model(m).MUA(i).rfs = R_EPHYS(r).model(m).MUA(i).rfsize;
  89. % convert pixels to degrees
  90. R_EPHYS(r).model(m).MUA(i).ecc = ...
  91. R_EPHYS(r).model(m).MUA(i).ecc .* R_EPHYS(r).model(m).MUA(i).Pix2Deg;
  92. R_EPHYS(r).model(m).MUA(i).rfs = ...
  93. R_EPHYS(r).model(m).MUA(i).rfs .* R_EPHYS(r).model(m).MUA(i).Pix2Deg;
  94. % calculate fwhm
  95. R_EPHYS(r).model(m).MUA(i).fwhm = ...
  96. R_EPHYS(r).model(m).MUA(i).rfs.*(2*sqrt(2*log(2)));
  97. F={'rfs','gain','R2','fwhm','sdratio','normamp','expt'};
  98. for f=1:length(F)
  99. if isfield(R_EPHYS(r).model(m).MUA(i), F{f})
  100. R_EPHYS(r).model(m).MUA(i).avg.(F{f}) = mean(R_EPHYS(r).model(m).MUA(i).(F{f}),2);
  101. end
  102. end
  103. % XY
  104. R_EPHYS(r).model(m).MUA(i).X = ...
  105. R_EPHYS(r).model(m).MUA(i).ecc.*cosd(R_EPHYS(r).model(m).MUA(i).ang);
  106. R_EPHYS(r).model(m).MUA(i).Y = ...
  107. R_EPHYS(r).model(m).MUA(i).ecc.*sind(R_EPHYS(r).model(m).MUA(i).ang);
  108. % avg XY
  109. R_EPHYS(r).model(m).MUA(i).avg.X=mean(R_EPHYS(r).model(m).MUA(i).X,2);
  110. R_EPHYS(r).model(m).MUA(i).avg.Y=mean(R_EPHYS(r).model(m).MUA(i).Y,2);
  111. R_EPHYS(r).model(m).MUA(i).avg.ecc=sqrt( ...
  112. R_EPHYS(r).model(m).MUA(i).avg.X.^2 + R_EPHYS(r).model(m).MUA(i).avg.Y.^2);
  113. % avg angle
  114. rawang = atand(R_EPHYS(r).model(m).MUA(i).avg.Y./R_EPHYS(r).model(m).MUA(i).avg.X);
  115. rawang(R_EPHYS(r).model(m).MUA(i).avg.X<0 & R_EPHYS(r).model(m).MUA(i).avg.Y<0) = ...
  116. rawang(R_EPHYS(r).model(m).MUA(i).avg.X<0 & R_EPHYS(r).model(m).MUA(i).avg.Y<0)-180;
  117. rawang(R_EPHYS(r).model(m).MUA(i).avg.X<0 & R_EPHYS(r).model(m).MUA(i).avg.Y>=0) = ...
  118. rawang(R_EPHYS(r).model(m).MUA(i).avg.X<0 & R_EPHYS(r).model(m).MUA(i).avg.Y>=0)+180;
  119. R_EPHYS(r).model(m).MUA(i).avg.ang = rawang;
  120. % dXY
  121. R_EPHYS(r).model(m).MUA(i).diff.XY = sqrt(...
  122. diff(R_EPHYS(r).model(m).MUA(i).X,1,2).^2 + ...
  123. diff(R_EPHYS(r).model(m).MUA(i).Y,1,2).^2);
  124. % dRFS
  125. R_EPHYS(r).model(m).MUA(i).diff.rfs = diff(R_EPHYS(r).model(m).MUA(i).rfs,1,2);
  126. % get maximum R2 version of some values
  127. [R_EPHYS(r).model(m).MUA(i).max.R2, R_EPHYS(r).model(m).MUA(i).max.R2_idx] = ...
  128. max(R_EPHYS(r).model(m).MUA(i).R2,[],2);
  129. R_EPHYS(r).model(m).MUA(i).max.R2_idx = ...
  130. [R_EPHYS(r).model(m).MUA(i).max.R2_idx==1,...
  131. R_EPHYS(r).model(m).MUA(i).max.R2_idx==2]';
  132. F={'rfs','gain','ecc','ang','fwhm','sdratio','normamp','expt'};
  133. for f=1:length(F)
  134. if isfield(R_EPHYS(r).model(m).MUA(i), F{f}) && ~isempty(R_EPHYS(r).model(m).MUA(i).(F{f}))
  135. TEMP = R_EPHYS(r).model(m).MUA(i).(F{f})';
  136. R_EPHYS(r).model(m).MUA(i).max.(F{f}) = ...
  137. TEMP(R_EPHYS(r).model(m).MUA(i).max.R2_idx);
  138. end
  139. end
  140. TEMPX = R_EPHYS(r).model(m).MUA(i).X';
  141. R_EPHYS(r).model(m).MUA(i).max.X = TEMPX(R_EPHYS(r).model(m).MUA(i).max.R2_idx);
  142. TEMPY = R_EPHYS(r).model(m).MUA(i).Y';
  143. R_EPHYS(r).model(m).MUA(i).max.Y = TEMPY(R_EPHYS(r).model(m).MUA(i).max.R2_idx);
  144. end
  145. if isfield(R_EPHYS(r).model(m).MUA,'rfsize')
  146. R_EPHYS(r).model(m).MUA = rmfield(R_EPHYS(r).model(m).MUA,'rfsize');
  147. end
  148. %% LFP --------------------------------------------------------
  149. fprintf('LFP\n');
  150. for fb=1:5
  151. for i = 1:8 % all instances
  152. % make name consistent with MRI
  153. R_EPHYS(r).model(m).LFP(i,fb).rfs = R_EPHYS(r).model(m).LFP(i,fb).rfsize;
  154. % convert pixels to degrees
  155. R_EPHYS(r).model(m).LFP(i,fb).ecc = ...
  156. R_EPHYS(r).model(m).LFP(i,fb).ecc .* R_EPHYS(r).model(m).LFP(i,fb).Pix2Deg;
  157. R_EPHYS(r).model(m).LFP(i,fb).rfs = ...
  158. R_EPHYS(r).model(m).LFP(i,fb).rfs .* R_EPHYS(r).model(m).LFP(i,fb).Pix2Deg;
  159. % calculate fwhm
  160. R_EPHYS(r).model(m).LFP(i,fb).fwhm = ...
  161. R_EPHYS(r).model(m).LFP(i,fb).rfs.*(2*sqrt(2*log(2)));
  162. F={'rfs','gain','R2','fwhm','sdratio','normamp','expt'};
  163. for f=1:length(F)
  164. if isfield(R_EPHYS(r).model(m).LFP(i,fb), F{f})
  165. R_EPHYS(r).model(m).LFP(i,fb).avg.(F{f}) = mean(R_EPHYS(r).model(m).LFP(i,fb).(F{f}),2);
  166. end
  167. end
  168. % XY
  169. R_EPHYS(r).model(m).LFP(i,fb).X = ...
  170. R_EPHYS(r).model(m).LFP(i,fb).ecc.*cosd(R_EPHYS(r).model(m).LFP(i,fb).ang);
  171. R_EPHYS(r).model(m).LFP(i,fb).Y = ...
  172. R_EPHYS(r).model(m).LFP(i,fb).ecc.*sind(R_EPHYS(r).model(m).LFP(i,fb).ang);
  173. % avg XY
  174. R_EPHYS(r).model(m).LFP(i,fb).avg.X=mean(R_EPHYS(r).model(m).LFP(i,fb).X,2);
  175. R_EPHYS(r).model(m).LFP(i,fb).avg.Y=mean(R_EPHYS(r).model(m).LFP(i,fb).Y,2);
  176. R_EPHYS(r).model(m).LFP(i,fb).avg.ecc=sqrt( ...
  177. R_EPHYS(r).model(m).LFP(i,fb).avg.X.^2 + R_EPHYS(r).model(m).LFP(i,fb).avg.Y.^2);
  178. % avg angle
  179. rawang = atand(R_EPHYS(r).model(m).LFP(i,fb).avg.Y./R_EPHYS(r).model(m).LFP(i,fb).avg.X);
  180. rawang(R_EPHYS(r).model(m).LFP(i,fb).avg.X<0 & R_EPHYS(r).model(m).LFP(i,fb).avg.Y<0) = ...
  181. rawang(R_EPHYS(r).model(m).LFP(i,fb).avg.X<0 & R_EPHYS(r).model(m).LFP(i,fb).avg.Y<0)-180;
  182. rawang(R_EPHYS(r).model(m).LFP(i,fb).avg.X<0 & R_EPHYS(r).model(m).LFP(i,fb).avg.Y>=0) = ...
  183. rawang(R_EPHYS(r).model(m).LFP(i,fb).avg.X<0 & R_EPHYS(r).model(m).LFP(i,fb).avg.Y>=0)+180;
  184. R_EPHYS(r).model(m).LFP(i,fb).avg.ang = rawang;
  185. % dXY
  186. R_EPHYS(r).model(m).LFP(i,fb).diff.XY = sqrt(...
  187. diff(R_EPHYS(r).model(m).LFP(i,fb).X,1,2).^2 + ...
  188. diff(R_EPHYS(r).model(m).LFP(i,fb).Y,1,2).^2);
  189. % dRFS
  190. R_EPHYS(r).model(m).LFP(i,fb).diff.rfs = diff(R_EPHYS(r).model(m).LFP(i,fb).rfs,1,2);
  191. % get maximum R2 version of some values
  192. [R_EPHYS(r).model(m).LFP(i,fb).max.R2, R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx] = ...
  193. max(R_EPHYS(r).model(m).LFP(i,fb).R2,[],2);
  194. R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx = ...
  195. [R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx==1,...
  196. R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx==2]';
  197. F={'rfs','gain','ecc','ang','fwhm','sdratio','normamp','expt'};
  198. for f=1:length(F)
  199. if isfield(R_EPHYS(r).model(m).LFP(i,fb), F{f}) && ~isempty(R_EPHYS(r).model(m).LFP(i,fb).(F{f}))
  200. TEMP = R_EPHYS(r).model(m).LFP(i,fb).(F{f})';
  201. R_EPHYS(r).model(m).LFP(i,fb).max.(F{f}) = ...
  202. TEMP(R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx);
  203. end
  204. end
  205. TEMPX = R_EPHYS(r).model(m).LFP(i,fb).X';
  206. R_EPHYS(r).model(m).LFP(i,fb).max.X = TEMPX(R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx);
  207. TEMPY = R_EPHYS(r).model(m).LFP(i,fb).Y';
  208. R_EPHYS(r).model(m).LFP(i,fb).max.Y = TEMPY(R_EPHYS(r).model(m).LFP(i,fb).max.R2_idx);
  209. end
  210. end
  211. if isfield(R_EPHYS(r).model(m).LFP,'rfsize')
  212. R_EPHYS(r).model(m).LFP = rmfield(R_EPHYS(r).model(m).LFP,'rfsize');
  213. end
  214. else % classic RF mapping
  215. fprintf('MUA\n');
  216. for i = 1:8 % instances
  217. for c = 1:length(R_EPHYS(r).model(m).MUA(i).RF) % channels
  218. if c == 1 % pre-allocate
  219. R_EPHYS(r).model(m).MUA(i).X = ...
  220. nan(length(R_EPHYS(r).model(m).MUA(i).RF),1);
  221. R_EPHYS(r).model(m).MUA(i).Y = ...
  222. nan(length(R_EPHYS(r).model(m).MUA(i).RF),1);
  223. R_EPHYS(r).model(m).MUA(i).rfs = ...
  224. nan(length(R_EPHYS(r).model(m).MUA(i).RF),1);
  225. R_EPHYS(r).model(m).MUA(i).ang = ...
  226. nan(length(R_EPHYS(r).model(m).MUA(i).RF),1);
  227. R_EPHYS(r).model(m).MUA(i).ecc = ...
  228. nan(length(R_EPHYS(r).model(m).MUA(i).RF),1);
  229. end
  230. % rfs / ang / ecc
  231. R_EPHYS(r).model(m).MUA(i).rfs(c) = ...
  232. R_EPHYS(r).model(m).MUA(i).RF{c}.szdeg;
  233. R_EPHYS(r).model(m).MUA(i).ang(c) = ...
  234. R_EPHYS(r).model(m).MUA(i).RF{c}.theta;
  235. R_EPHYS(r).model(m).MUA(i).ecc(c) = ...
  236. R_EPHYS(r).model(m).MUA(i).RF{c}.ecc;
  237. % XY
  238. PixPerDeg = R_EPHYS(r).model(m).MUA(i).RF{c}.sz./...
  239. R_EPHYS(r).model(m).MUA(i).RF{c}.szdeg;
  240. R_EPHYS(r).model(m).MUA(i).X(c) = ...
  241. R_EPHYS(r).model(m).MUA(i).RF{c}.centrex./PixPerDeg;
  242. R_EPHYS(r).model(m).MUA(i).Y(c) = ...
  243. R_EPHYS(r).model(m).MUA(i).RF{c}.centrey./PixPerDeg;
  244. end
  245. % fwhm
  246. R_EPHYS(r).model(m).MUA(i).fwhm = ...
  247. R_EPHYS(r).model(m).MUA(i).rfs.*(2*sqrt(2*log(2)));
  248. end
  249. end
  250. end
  251. % ChannelMapping =====
  252. fprintf('Collecting the channel-map\n')
  253. CM = []; cm = R_EPHYS(r).ChanMap;
  254. for i = 1:size(cm.arrayNums,2) % instances
  255. for ch = 1:size(cm.arrayNums,1) % channels
  256. CM=[CM;...
  257. i ch ...
  258. cm.arrayNums(ch,i) cm.channelNums(ch,i) cm.areas(ch,i) ];
  259. end
  260. end
  261. R_EPHYS(r).cm = CM;
  262. end
  263. %% Create a bunch of tables with all results ==============================
  264. % MRI ---
  265. % Only brain voxels
  266. fprintf('\n==============================\n')
  267. fprintf('Creating combined tables...\n')
  268. fprintf('==============================\n')
  269. %% MRI --------------------------------------------------------------------
  270. fprintf('MRI ==\n');
  271. for r = 1:length(R_MRI) % animals
  272. % brain voxels logical
  273. bm=R_MRI(r).Brainmask;
  274. %create tables
  275. for m = 1:length(R_MRI(r).model) % model fits
  276. if r==1 && m==1
  277. % start the structures
  278. RTMm.Monkey =[]; RTMm.Mode =[]; RTMm.Model =[];
  279. RTMm.ROI = [];
  280. RTMm.ELEC_V1 = []; RTMm.ELEC_V4 = [];
  281. RTMm.R2 = []; RTMm.rfs = []; RTMm.fwhm = [];
  282. RTMm.X = []; RTMm.Y = [];
  283. RTMm.ang = []; RTMm.ecc = [];
  284. % not for all
  285. RTMm.expt = []; RTMm.sdratio = [];
  286. RTMm.gain = []; RTMm.normamp = [];
  287. RTM.Monkey =[]; RTM.Mode =[]; RTM.Model =[];
  288. RTM.ROI = [];
  289. RTM.ELEC_V1 = []; RTM.ELEC_V4 = [];
  290. RTM.R2_1 = []; RTM.rfs_1 = []; RTM.fwhm_1 = [];
  291. RTM.X_1 = []; RTM.Y_1 = [];
  292. RTM.ang_1 = []; RTM.ecc_1 = [];
  293. RTM.R2_2 = []; RTM.rfs_2 = []; RTM.fwhm_2 = [];
  294. RTM.X_2 = []; RTM.Y_2 = [];
  295. RTM.ang_2 = []; RTM.ecc_2 = [];
  296. RTM.dXY=[]; RTM.dRFS = [];
  297. RTM.gain_1=[]; RTM.gain_2=[];
  298. RTM.expt_1 =[]; RTM.expt_2 =[];
  299. RTM.sdratio_1 = []; RTM.sdratio_2 = [];
  300. RTM.normamp_1 = []; RTM.normamp_2 = [];
  301. end
  302. nVox = sum(bm);
  303. % mean ====
  304. % labels
  305. RTMm_Monkey = cell(nVox,1);
  306. RTMm_Mode = cell(nVox,1);
  307. RTMm_Model = cell(nVox,1);
  308. for n=1:nVox
  309. RTMm_Monkey{n}=R_MRI(r).monkey;
  310. RTMm_Mode{n}=R_MRI(r).mode;
  311. RTMm_Model{n}=R_MRI(r).model(m).prfmodel;
  312. end
  313. RTMm.Monkey = cat(1,RTMm.Monkey,RTMm_Monkey);
  314. RTMm.Mode = cat(1,RTMm.Mode,RTMm_Mode);
  315. RTMm.Model = cat(1,RTMm.Model,RTMm_Model);
  316. % values
  317. RTMm.ROI = cat(1,RTMm.ROI,R_MRI(r).ROI(bm));
  318. RTMm.ELEC_V1 = cat(1,RTMm.ELEC_V1,R_MRI(r).ELECTR_V1(bm));
  319. RTMm.ELEC_V4 = cat(1,RTMm.ELEC_V4,R_MRI(r).ELECTR_V4(bm));
  320. RTMm.rfs = cat(1,RTMm.rfs,R_MRI(r).model(m).avg.rfs(bm)');
  321. RTMm.fwhm = cat(1,RTMm.fwhm,R_MRI(r).model(m).avg.fwhm(bm)');
  322. RTMm.X = cat(1,RTMm.X,R_MRI(r).model(m).avg.X(bm)');
  323. RTMm.Y = cat(1,RTMm.Y,R_MRI(r).model(m).avg.Y(bm)');
  324. RTMm.ang = cat(1,RTMm.ang,R_MRI(r).model(m).avg.ang(bm)');
  325. RTMm.ecc = cat(1,RTMm.ecc,R_MRI(r).model(m).avg.ecc(bm)');
  326. % optional fields
  327. if isfield(R_MRI(r).model(m).avg,'R2')
  328. RTMm.R2 = cat(1,RTMm.R2,R_MRI(r).model(m).avg.R2(bm)');
  329. else
  330. RTMm.R2 = cat(1,RTMm.R2,nan(nVox,1));
  331. end
  332. if isfield(R_MRI(r).model(m).avg,'gain')
  333. RTMm.gain = cat(1,RTMm.gain,R_MRI(r).model(m).avg.gain(bm)');
  334. else
  335. RTMm.gain = cat(1,RTMm.gain,nan(nVox,1));
  336. end
  337. if isfield(R_MRI(r).model(m).avg,'expt')
  338. RTMm.expt = cat(1,RTMm.expt,R_MRI(r).model(m).avg.expt(bm)');
  339. else
  340. RTMm.expt = cat(1,RTMm.expt,nan(nVox,1));
  341. end
  342. if isfield(R_MRI(r).model(m).avg,'sdratio')
  343. RTMm.sdratio = cat(1,RTMm.sdratio,R_MRI(r).model(m).avg.sdratio(bm)');
  344. else
  345. RTMm.sdratio = cat(1,RTMm.sdratio,nan(nVox,1));
  346. end
  347. if isfield(R_MRI(r).model(m).avg,'normamp')
  348. RTMm.normamp = cat(1,RTMm.normamp,R_MRI(r).model(m).avg.normamp(bm)');
  349. else
  350. RTMm.normamp = cat(1,RTMm.normamp,nan(nVox,1));
  351. end
  352. % diff ====
  353. % labels
  354. RTM.Monkey = RTMm.Monkey;
  355. RTM.Mode = RTMm.Mode;
  356. RTM.Model = RTMm.Model;
  357. % values
  358. RTM.ROI = cat(1,RTM.ROI,R_MRI(r).ROI(bm));
  359. RTM.ELEC_V1 = cat(1,RTM.ELEC_V1,R_MRI(r).ELECTR_V1(bm));
  360. RTM.ELEC_V4 = cat(1,RTM.ELEC_V4,R_MRI(r).ELECTR_V4(bm));
  361. RTM.rfs_1 = cat(1,RTM.rfs_1,R_MRI(r).model(m).rfs(1,bm)');
  362. RTM.rfs_2 = cat(1,RTM.rfs_2,R_MRI(r).model(m).rfs(2,bm)');
  363. RTM.fwhm_1 = cat(1,RTM.fwhm_1,R_MRI(r).model(m).fwhm(1,bm)');
  364. RTM.fwhm_2 = cat(1,RTM.fwhm_2,R_MRI(r).model(m).fwhm(2,bm)');
  365. RTM.X_1 = cat(1,RTM.X_1,R_MRI(r).model(m).X(1,bm)');
  366. RTM.X_2 = cat(1,RTM.X_2,R_MRI(r).model(m).X(2,bm)');
  367. RTM.Y_1 = cat(1,RTM.Y_1,R_MRI(r).model(m).Y(1,bm)');
  368. RTM.Y_2 = cat(1,RTM.Y_2,R_MRI(r).model(m).Y(2,bm)');
  369. RTM.ang_1 = cat(1,RTM.ang_1,R_MRI(r).model(m).ang(1,bm)');
  370. RTM.ang_2 = cat(1,RTM.ang_2,R_MRI(r).model(m).ang(2,bm)');
  371. RTM.ecc_1 = cat(1,RTM.ecc_1,R_MRI(r).model(m).ecc(1,bm)');
  372. RTM.ecc_2 = cat(1,RTM.ecc_2,R_MRI(r).model(m).ecc(2,bm)');
  373. RTM.dXY = cat(1,RTM.dXY,R_MRI(r).model(m).diff.XY(bm)');
  374. RTM.dRFS = cat(1,RTM.dRFS,R_MRI(r).model(m).diff.rfs(bm)');
  375. % optional fields
  376. if isfield(R_MRI(r).model,'R2') && ~isempty(R_MRI(r).model(m).R2)
  377. RTM.R2_1 = cat(1,RTM.R2_1,R_MRI(r).model(m).R2(1,bm)');
  378. RTM.R2_2 = cat(1,RTM.R2_2,R_MRI(r).model(m).R2(2,bm)');
  379. else
  380. RTM.R2_1 = cat(1,RTM.R2_1,nan(nVox,1));
  381. RTM.R2_2 = cat(1,RTM.R2_2,nan(nVox,1));
  382. end
  383. if isfield(R_MRI(r).model,'gain') && ~isempty(R_MRI(r).model(m).gain)
  384. RTM.gain_1 = cat(1,RTM.gain_1,R_MRI(r).model(m).gain(1,bm)');
  385. RTM.gain_2 = cat(1,RTM.gain_2,R_MRI(r).model(m).gain(2,bm)');
  386. else
  387. RTM.gain_1 = cat(1,RTM.gain_1,nan(nVox,1));
  388. RTM.gain_2 = cat(1,RTM.gain_2,nan(nVox,1));
  389. end
  390. if isfield(R_MRI(r).model,'expt') && ~isempty(R_MRI(r).model(m).expt)
  391. RTM.expt_1 = cat(1,RTM.expt_1,R_MRI(r).model(m).expt(1,bm)');
  392. RTM.expt_2 = cat(1,RTM.expt_2,R_MRI(r).model(m).expt(2,bm)');
  393. else
  394. RTM.expt_1 = cat(1,RTM.expt_1,nan(nVox,1));
  395. RTM.expt_2 = cat(1,RTM.expt_2,nan(nVox,1));
  396. end
  397. if isfield(R_MRI(r).model,'sdratio') && ~isempty(R_MRI(r).model(m).sdratio)
  398. RTM.sdratio_1 = cat(1,RTM.sdratio_1,R_MRI(r).model(m).sdratio(1,bm)');
  399. RTM.sdratio_2 = cat(1,RTM.sdratio_2,R_MRI(r).model(m).sdratio(2,bm)');
  400. else
  401. RTM.sdratio_1 = cat(1,RTM.sdratio_1,nan(nVox,1));
  402. RTM.sdratio_2 = cat(1,RTM.sdratio_2,nan(nVox,1));
  403. end
  404. if isfield(R_MRI(r).model,'normamp') && ~isempty(R_MRI(r).model(m).normamp)
  405. RTM.normamp_1 = cat(1,RTM.normamp_1,R_MRI(r).model(m).normamp(1,bm)');
  406. RTM.normamp_2 = cat(1,RTM.normamp_2,R_MRI(r).model(m).normamp(2,bm)');
  407. else
  408. RTM.normamp_1 = cat(1,RTM.normamp_1,nan(nVox,1));
  409. RTM.normamp_2 = cat(1,RTM.normamp_2,nan(nVox,1));
  410. end
  411. end
  412. end
  413. tMRI = struct2table(RTM);
  414. tMRI_mean = struct2table(RTMm);
  415. MRI.RTE = RTM;
  416. MRI.RTEm = RTMm;
  417. %% EPHYS MUA --------------------------------------------------------------
  418. fprintf('EPHYS MUA ==\n');
  419. for r = 1:length(R_EPHYS) % animals
  420. %create tables
  421. for m = 1:length(R_EPHYS(r).model) % model fits
  422. if r==1 && m==1
  423. % start the structures
  424. % labels
  425. RTEm.Monkey =[]; RTEm.Mode = [];
  426. RTEm.Model = []; RTEm.SigType = [];
  427. RTEm.Array = []; RTEm.Chan = []; RTEm.Area = [];
  428. % results
  429. RTEm.R2 = []; RTEm.rfs = []; RTEm.fwhm = [];
  430. RTEm.X = []; RTEm.Y = [];
  431. RTEm.ang = []; RTEm.ecc = [];
  432. % not for all
  433. RTEm.expt =[]; RTEm.sdratio = [];
  434. RTEm.gain = []; RTEm.normamp = [];
  435. RTEm.SNR = [];
  436. %
  437. RTE.R2_1 = []; RTE.rfs_1 = []; RTE.fwhm_1 = [];
  438. RTE.X_1 = []; RTE.Y_1 = [];
  439. RTE.ang_1 = []; RTE.ecc_1 = [];
  440. RTE.R2_2 = []; RTE.rfs_2 = []; RTE.fwhm_2 = [];
  441. RTE.X_2 = []; RTE.Y_2 = [];
  442. RTE.ang_2 = []; RTE.ecc_2 = [];
  443. RTE.Monkey =[]; RTE.Mode = [];
  444. RTE.Model = []; RTE.SigType = [];
  445. RTE.Array = []; RTE.Chan = []; RTE.Area = [];
  446. RTE.gain_1 = []; RTE.gain_2 = [];
  447. RTE.expt_1 =[]; RTE.expt_2 =[];
  448. RTE.sdratio_1 = []; RTE.sdratio_2 = [];
  449. RTE.normamp_1 = []; RTE.normamp_2 = [];
  450. RTE.dXY=[]; RTE.dRFS = [];
  451. RTE.SNR = [];
  452. end
  453. nChan = size(R_EPHYS(1).model(1).MUA(1).ang,1);
  454. nInst = length(R_EPHYS(1).model(1).MUA);
  455. % MUA ---------
  456. % labels
  457. RTEm_Monkey = cell(nChan*nInst,1); i=1;
  458. for ni = 1:nInst
  459. for n=1:nChan
  460. RTEm_Monkey{i} = R_EPHYS(r).monkey;
  461. i=i+1;
  462. end
  463. end
  464. RTEm.Monkey = cat(1,RTEm.Monkey,RTEm_Monkey);
  465. %--
  466. RTEm_Mode = cell(nChan*nInst,1); i=1;
  467. for ni = 1:nInst
  468. for n=1:nChan
  469. RTEm_Mode{i} = R_EPHYS(r).mode;
  470. i=i+1;
  471. end
  472. end
  473. RTEm.Mode = cat(1,RTEm.Mode,RTEm_Mode);
  474. %--
  475. RTEm_Model = cell(nChan*nInst,1); i=1;
  476. for ni = 1:nInst
  477. for n=1:nChan
  478. RTEm_Model{i} = R_EPHYS(r).model(m).prfmodel;
  479. i=i+1;
  480. end
  481. end
  482. RTEm.Model = cat(1,RTEm.Model,RTEm_Model);
  483. %--
  484. RTEm_SigType = cell(nChan*nInst,1); i=1;
  485. for ni = 1:nInst
  486. for n=1:nChan
  487. RTEm_SigType{i} = 'MUA';
  488. i=i+1;
  489. end
  490. end
  491. RTEm.SigType = cat(1,RTEm.SigType,RTEm_SigType);
  492. %--
  493. if m==1
  494. RTEm_Array = repmat(R_EPHYS(r).cm(:,3),length(R_EPHYS(r).model),1);
  495. RTEm.Array = cat(1,RTEm.Array,RTEm_Array);
  496. RTEm_Chan = repmat(R_EPHYS(r).cm(:,4),length(R_EPHYS(r).model),1);
  497. RTEm.Chan = cat(1,RTEm.Chan,RTEm_Chan);
  498. RTEm_Area = repmat(R_EPHYS(r).cm(:,5),length(R_EPHYS(r).model),1);
  499. RTEm.Area = cat(1,RTEm.Area,RTEm_Area);
  500. end
  501. %--
  502. for i=1:nInst
  503. if strcmp(R_EPHYS(r).model(m).prfmodel,'classicRF')
  504. % standard fields
  505. RTEm.rfs = cat(1,RTEm.rfs,R_EPHYS(r).model(m).MUA(i).rfs);
  506. RTEm.fwhm = cat(1,RTEm.fwhm,R_EPHYS(r).model(m).MUA(i).fwhm);
  507. RTEm.X = cat(1,RTEm.X,R_EPHYS(r).model(m).MUA(i).X);
  508. RTEm.Y = cat(1,RTEm.Y,R_EPHYS(r).model(m).MUA(i).Y);
  509. RTEm.ang = cat(1,RTEm.ang,R_EPHYS(r).model(m).MUA(i).ang);
  510. RTEm.ecc = cat(1,RTEm.ecc,R_EPHYS(r).model(m).MUA(i).ecc);
  511. % optional fields
  512. RTEm.R2 = cat(1,RTEm.R2,R_EPHYS(r).model(m).MUA(i).R2);
  513. %RTEm.R2 = cat(1,RTEm.R2,nan(nChan,1));
  514. RTEm.gain = cat(1,RTEm.gain,nan(nChan,1));
  515. RTEm.expt = cat(1,RTEm.expt,nan(nChan,1));
  516. RTEm.sdratio = cat(1,RTEm.sdratio,nan(nChan,1));
  517. RTEm.normamp = cat(1,RTEm.normamp,nan(nChan,1));
  518. RTEm.SNR = cat(1,RTEm.SNR,R_EPHYS(r).model(m).MUA(i).SNR);
  519. else
  520. % standard fields
  521. RTEm.rfs = cat(1,RTEm.rfs,R_EPHYS(r).model(m).MUA(i).avg.rfs);
  522. RTEm.fwhm = cat(1,RTEm.fwhm,R_EPHYS(r).model(m).MUA(i).avg.fwhm);
  523. RTEm.X = cat(1,RTEm.X,R_EPHYS(r).model(m).MUA(i).avg.X);
  524. RTEm.Y = cat(1,RTEm.Y,R_EPHYS(r).model(m).MUA(i).avg.Y);
  525. RTEm.ang = cat(1,RTEm.ang,R_EPHYS(r).model(m).MUA(i).avg.ang);
  526. RTEm.ecc = cat(1,RTEm.ecc,R_EPHYS(r).model(m).MUA(i).avg.ecc);
  527. % optional fields
  528. if isfield(R_EPHYS(r).model(m).MUA(i).avg,'R2')
  529. RTEm.R2 = cat(1,RTEm.R2,R_EPHYS(r).model(m).MUA(i).avg.R2);
  530. else
  531. RTEm.R2 = cat(1,RTEm.R2,nan(nChan,1));
  532. end
  533. if isfield(R_EPHYS(r).model(m).MUA(i).avg,'gain')
  534. RTEm.gain = cat(1,RTEm.gain,R_EPHYS(r).model(m).MUA(i).avg.gain);
  535. else
  536. RTEm.gain = cat(1,RTEm.gain,nan(nChan,1));
  537. end
  538. if isfield(R_EPHYS(r).model(m).MUA(i).avg,'expt')
  539. RTEm.expt = cat(1,RTEm.expt,R_EPHYS(r).model(m).MUA(i).avg.expt);
  540. else
  541. RTEm.expt = cat(1,RTEm.expt,nan(nChan,1));
  542. end
  543. if isfield(R_EPHYS(r).model(m).MUA(i).avg,'sdratio')
  544. RTEm.sdratio = cat(1,RTEm.sdratio,R_EPHYS(r).model(m).MUA(i).avg.sdratio);
  545. else
  546. RTEm.sdratio = cat(1,RTEm.sdratio,nan(nChan,1));
  547. end
  548. if isfield(R_EPHYS(r).model(m).MUA(i).avg,'normamp')
  549. RTEm.normamp = cat(1,RTEm.normamp,R_EPHYS(r).model(m).MUA(i).avg.normamp);
  550. else
  551. RTEm.normamp = cat(1,RTEm.normamp,nan(nChan,1));
  552. end
  553. if isfield(R_EPHYS(r).model(m).MUA(i),'SNR')
  554. RTEm.SNR = cat(1,RTEm.SNR,R_EPHYS(r).model(m).MUA(i).SNR);
  555. else
  556. RTEm.SNR = cat(1,RTEm.SNR,nan(nChan,1));
  557. end
  558. end
  559. end
  560. % diff ====
  561. for i=1:nInst % exclude classic RF here (no point in adding)
  562. if ~strcmp(R_EPHYS(r).model(m).prfmodel,'classicRF')
  563. % standard fields
  564. RTE.rfs_1 = cat(1,RTE.rfs_1,R_EPHYS(r).model(m).MUA(i).rfs(:,1));
  565. RTE.fwhm_1 = cat(1,RTE.fwhm_1,R_EPHYS(r).model(m).MUA(i).fwhm(:,1));
  566. RTE.X_1 = cat(1,RTE.X_1,R_EPHYS(r).model(m).MUA(i).X(:,1));
  567. RTE.Y_1 = cat(1,RTE.Y_1,R_EPHYS(r).model(m).MUA(i).Y(:,1));
  568. RTE.ang_1 = cat(1,RTE.ang_1,R_EPHYS(r).model(m).MUA(i).ang(:,1));
  569. RTE.ecc_1 = cat(1,RTE.ecc_1,R_EPHYS(r).model(m).MUA(i).ecc(:,1));
  570. %--
  571. RTE.rfs_2 = cat(1,RTE.rfs_2,R_EPHYS(r).model(m).MUA(i).rfs(:,2));
  572. RTE.fwhm_2 = cat(1,RTE.fwhm_2,R_EPHYS(r).model(m).MUA(i).fwhm(:,2));
  573. RTE.X_2 = cat(1,RTE.X_2,R_EPHYS(r).model(m).MUA(i).X(:,2));
  574. RTE.Y_2 = cat(1,RTE.Y_2,R_EPHYS(r).model(m).MUA(i).Y(:,2));
  575. RTE.ang_2 = cat(1,RTE.ang_2,R_EPHYS(r).model(m).MUA(i).ang(:,2));
  576. RTE.ecc_2 = cat(1,RTE.ecc_2,R_EPHYS(r).model(m).MUA(i).ecc(:,2));
  577. %--
  578. RTE.dXY = cat(1,RTE.dXY,R_EPHYS(r).model(m).MUA(i).diff.XY);
  579. RTE.dRFS = cat(1,RTE.dRFS,R_EPHYS(r).model(m).MUA(i).diff.rfs);
  580. %--
  581. % optional fields
  582. if isfield(R_EPHYS(r).model(m).MUA,'R2')
  583. RTE.R2_1 = cat(1,RTE.R2_1,R_EPHYS(r).model(m).MUA(i).R2(:,1));
  584. RTE.R2_2 = cat(1,RTE.R2_2,R_EPHYS(r).model(m).MUA(i).R2(:,2));
  585. else
  586. RTE.R2_1 = cat(1,RTE.R2_1,nan(nChan,1));
  587. RTE.R2_2 = cat(1,RTE.R2_2,nan(nChan,1));
  588. end
  589. if isfield(R_EPHYS(r).model(m).MUA,'gain')
  590. RTE.gain_1 = cat(1,RTE.gain_1,R_EPHYS(r).model(m).MUA(i).gain(:,1));
  591. RTE.gain_2 = cat(1,RTE.gain_2,R_EPHYS(r).model(m).MUA(i).gain(:,2));
  592. else
  593. RTE.gain_1 = cat(1,RTE.gain_1,nan(nChan,1));
  594. RTE.gain_2 = cat(1,RTE.gain_2,nan(nChan,1));
  595. end
  596. if isfield(R_EPHYS(r).model(m).MUA,'expt')
  597. RTE.expt_1 = cat(1,RTE.expt_1,R_EPHYS(r).model(m).MUA(i).expt(:,1));
  598. RTE.expt_2 = cat(1,RTE.expt_2,R_EPHYS(r).model(m).MUA(i).expt(:,2));
  599. else
  600. RTE.expt_1 = cat(1,RTE.expt_1,nan(nChan,1));
  601. RTE.expt_2 = cat(1,RTE.expt_2,nan(nChan,1));
  602. end
  603. if isfield(R_EPHYS(r).model(m).MUA,'sdratio')
  604. RTE.sdratio_1 = cat(1,RTE.sdratio_1,R_EPHYS(r).model(m).MUA(i).sdratio(:,1));
  605. RTE.sdratio_2 = cat(1,RTE.sdratio_2,R_EPHYS(r).model(m).MUA(i).sdratio(:,2));
  606. else
  607. RTE.sdratio_1 = cat(1,RTE.sdratio_1,nan(nChan,1));
  608. RTE.sdratio_2 = cat(1,RTE.sdratio_2,nan(nChan,1));
  609. end
  610. if isfield(R_EPHYS(r).model(m).MUA,'normamp')
  611. RTE.normamp_1 = cat(1,RTE.normamp_1,R_EPHYS(r).model(m).MUA(i).normamp(:,1));
  612. RTE.normamp_2 = cat(1,RTE.normamp_2,R_EPHYS(r).model(m).MUA(i).normamp(:,2));
  613. else
  614. RTE.normamp_1 = cat(1,RTE.normamp_1,nan(nChan,1));
  615. RTE.normamp_2 = cat(1,RTE.normamp_2,nan(nChan,1));
  616. end
  617. if isfield(R_EPHYS(r).model(m).MUA(i),'SNR')
  618. RTE.SNR = cat(1,RTE.SNR,R_EPHYS(r).model(m).MUA(i).SNR);
  619. else
  620. RTE.SNR = cat(1,RTE.SNR,nan(nChan,1));
  621. end
  622. end
  623. end
  624. end
  625. % remove the last modeltype from label fields where you don't want them
  626. nRows = nInst*nChan;
  627. sp=(r-1)*length(R_EPHYS(r).model)*nRows;
  628. RTE.Monkey = cat(1,RTE.Monkey,RTEm.Monkey(sp+1:end-nRows,:));
  629. RTE.Mode = cat(1,RTE.Mode,RTEm.Mode(sp+1:end-nRows,:));
  630. RTE.Model = cat(1,RTE.Model,RTEm.Model(sp+1:end-nRows,:));
  631. RTE.SigType = cat(1,RTE.SigType,RTEm.SigType(sp+1:end-nRows,:));
  632. RTE.Array = cat(1,RTE.Array,RTEm.Array(sp+1:end-nRows,:));
  633. RTE.Chan = cat(1,RTE.Chan,RTEm.Chan(sp+1:end-nRows,:));
  634. RTE.Area = cat(1,RTE.Area,RTEm.Area(sp+1:end-nRows,:));
  635. end
  636. tMUA = struct2table(RTE);
  637. tMUA_mean = struct2table(RTEm);
  638. MUA.RTE = RTE;
  639. MUA.RTEm = RTEm;
  640. %% EPHYS LFP --------------------------------------------------------------
  641. LFPlabels = {'Theta','Alpha','Beta','lGamma','hGamma'};
  642. fprintf('EPHYS LFP ==\n');
  643. for r = 1:length(R_EPHYS) % animals
  644. %create tables
  645. for m = 1:length(R_EPHYS(r).model)-1 % model fits (skip the last)
  646. if r==1 && m==1
  647. % start the structures
  648. % labels
  649. RTEm.Monkey =[]; RTEm.Mode = [];
  650. RTEm.Model = []; RTEm.SigType = [];
  651. RTEm.Array = []; RTEm.Chan = []; RTEm.Area = [];
  652. % results
  653. RTEm.R2 = []; RTEm.rfs = []; RTEm.fwhm = [];
  654. RTEm.X = []; RTEm.Y = [];
  655. RTEm.ang = []; RTEm.ecc = [];
  656. % not for all
  657. RTEm.expt =[]; RTEm.sdratio = [];
  658. RTEm.gain = []; RTEm.normamp = [];
  659. RTEm.SNR = [];
  660. RTE.R2_1 = []; RTE.rfs_1 = []; RTE.fwhm_1 = [];
  661. RTE.X_1 = []; RTE.Y_1 = [];
  662. RTE.ang_1 = []; RTE.ecc_1 = [];
  663. RTE.R2_2 = []; RTE.rfs_2 = []; RTE.fwhm_2 = [];
  664. RTE.X_2 = []; RTE.Y_2 = [];
  665. RTE.ang_2 = []; RTE.ecc_2 = [];
  666. RTE.Monkey =[]; RTE.Mode = [];
  667. RTE.Model = []; RTE.SigType = [];
  668. RTE.Array = []; RTE.Chan = []; RTE.Area = [];
  669. RTE.gain_1 = []; RTE.gain_2 = [];
  670. RTE.expt_1 =[]; RTE.expt_2 =[];
  671. RTE.sdratio_1 = []; RTE.sdratio_2 = [];
  672. RTE.normamp_1 = []; RTE.normamp_2 = [];
  673. RTE.dXY=[]; RTE.dRFS = [];
  674. RTE.SNR = [];
  675. end
  676. nChan = size(R_EPHYS(1).model(1).LFP(1).ang,1);
  677. nInst = size(R_EPHYS(1).model(1).LFP,1);
  678. nFB = size(R_EPHYS(1).model(1).LFP,2);
  679. nMod = length(R_EPHYS(r).model)-1;
  680. % LFP ---------
  681. % labels
  682. RTEm_Monkey = cell(nChan*nInst,1); i=1;
  683. for ni = 1:nInst
  684. for n=1:nChan
  685. for f=1:nFB
  686. RTEm_Monkey{i} = R_EPHYS(r).monkey;
  687. i=i+1;
  688. end
  689. end
  690. end
  691. RTEm.Monkey = cat(1,RTEm.Monkey,RTEm_Monkey);
  692. %--
  693. RTEm_Mode = cell(nChan*nInst,1); i=1;
  694. for ni = 1:nInst
  695. for n=1:nChan
  696. for f=1:nFB
  697. RTEm_Mode{i} = R_EPHYS(r).mode;
  698. i=i+1;
  699. end
  700. end
  701. end
  702. RTEm.Mode = cat(1,RTEm.Mode,RTEm_Mode);
  703. %--
  704. RTEm_Model = cell(nChan*nInst,1); i=1;
  705. for ni = 1:nInst
  706. for n=1:nChan
  707. for f=1:nFB
  708. RTEm_Model{i} = R_EPHYS(r).model(m).prfmodel;
  709. i=i+1;
  710. end
  711. end
  712. end
  713. RTEm.Model = cat(1,RTEm.Model,RTEm_Model);
  714. %--
  715. RTEm_SigType = cell(nChan*nInst,1); i=1;
  716. for f=1:nFB
  717. for ni = 1:nInst
  718. for n=1:nChan
  719. RTEm_SigType{i} = LFPlabels{f};
  720. i=i+1;
  721. end
  722. end
  723. end
  724. RTEm.SigType = cat(1,RTEm.SigType,RTEm_SigType);
  725. %--
  726. if m==1
  727. RTEm_Array=[];
  728. RTEm_Chan=[];
  729. RTEm_Area=[];
  730. for f=1:nFB
  731. RTEm_Array=[RTEm_Array; R_EPHYS(r).cm(:,3)];
  732. RTEm_Chan=[RTEm_Chan; R_EPHYS(r).cm(:,4)];
  733. RTEm_Area=[RTEm_Area; R_EPHYS(r).cm(:,5)];
  734. end
  735. RTEm.Array = [RTEm.Array; repmat(RTEm_Array,nMod,1)];
  736. RTEm.Chan = [RTEm.Chan; repmat(RTEm_Chan,nMod,1)];
  737. RTEm.Area = [RTEm.Area; repmat(RTEm_Area,nMod,1)];
  738. end
  739. %--
  740. for f=1:nFB
  741. for i=1:nInst
  742. % standard fields
  743. RTEm.rfs = cat(1,RTEm.rfs,R_EPHYS(r).model(m).LFP(i,f).avg.rfs);
  744. RTEm.fwhm = cat(1,RTEm.fwhm,R_EPHYS(r).model(m).LFP(i,f).avg.fwhm);
  745. RTEm.X = cat(1,RTEm.X,R_EPHYS(r).model(m).LFP(i,f).avg.X);
  746. RTEm.Y = cat(1,RTEm.Y,R_EPHYS(r).model(m).LFP(i,f).avg.Y);
  747. RTEm.ang = cat(1,RTEm.ang,R_EPHYS(r).model(m).LFP(i,f).avg.ang);
  748. RTEm.ecc = cat(1,RTEm.ecc,R_EPHYS(r).model(m).LFP(i,f).avg.ecc);
  749. % optional fields
  750. if isfield(R_EPHYS(r).model(m).LFP(i,f).avg,'R2')
  751. RTEm.R2 = cat(1,RTEm.R2,R_EPHYS(r).model(m).LFP(i,f).avg.R2);
  752. else
  753. RTEm.R2 = cat(1,RTEm.R2,nan(nChan,1));
  754. end
  755. if isfield(R_EPHYS(r).model(m).LFP(i,f).avg,'gain')
  756. RTEm.gain = cat(1,RTEm.gain,R_EPHYS(r).model(m).LFP(i,f).avg.gain);
  757. else
  758. RTEm.gain = cat(1,RTEm.gain,nan(nChan,1));
  759. end
  760. if isfield(R_EPHYS(r).model(m).LFP(i,f).avg,'expt')
  761. RTEm.expt = cat(1,RTEm.expt,R_EPHYS(r).model(m).LFP(i,f).avg.expt);
  762. else
  763. RTEm.expt = cat(1,RTEm.expt,nan(nChan,1));
  764. end
  765. if isfield(R_EPHYS(r).model(m).LFP(i,f).avg,'sdratio')
  766. RTEm.sdratio = cat(1,RTEm.sdratio,R_EPHYS(r).model(m).LFP(i,f).avg.sdratio);
  767. else
  768. RTEm.sdratio = cat(1,RTEm.sdratio,nan(nChan,1));
  769. end
  770. if isfield(R_EPHYS(r).model(m).LFP(i,f).avg,'normamp')
  771. RTEm.normamp = cat(1,RTEm.normamp,R_EPHYS(r).model(m).LFP(i,f).avg.normamp);
  772. else
  773. RTEm.normamp = cat(1,RTEm.normamp,nan(nChan,1));
  774. end
  775. if isfield(R_EPHYS(r).model(m).LFP(i,f),'SNR')
  776. RTEm.SNR = cat(1,RTEm.SNR,R_EPHYS(r).model(m).LFP(i,f).SNR);
  777. else
  778. RTEm.SNR = cat(1,RTEm.SNR,nan(nChan,1));
  779. end
  780. end
  781. end
  782. % diff ====
  783. %--
  784. for f=1:nFB
  785. for i=1:nInst
  786. % standard fields
  787. RTE.rfs_1 = cat(1,RTE.rfs_1,R_EPHYS(r).model(m).LFP(i,f).rfs(:,1));
  788. RTE.fwhm_1 = cat(1,RTE.fwhm_1,R_EPHYS(r).model(m).LFP(i,f).fwhm(:,1));
  789. RTE.X_1 = cat(1,RTE.X_1,R_EPHYS(r).model(m).LFP(i,f).X(:,1));
  790. RTE.Y_1 = cat(1,RTE.Y_1,R_EPHYS(r).model(m).LFP(i,f).Y(:,1));
  791. RTE.ang_1 = cat(1,RTE.ang_1,R_EPHYS(r).model(m).LFP(i,f).ang(:,1));
  792. RTE.ecc_1 = cat(1,RTE.ecc_1,R_EPHYS(r).model(m).LFP(i,f).ecc(:,1));
  793. %--
  794. RTE.rfs_2 = cat(1,RTE.rfs_2,R_EPHYS(r).model(m).LFP(i,f).rfs(:,2));
  795. RTE.fwhm_2 = cat(1,RTE.fwhm_2,R_EPHYS(r).model(m).LFP(i,f).fwhm(:,2));
  796. RTE.X_2 = cat(1,RTE.X_2,R_EPHYS(r).model(m).LFP(i,f).X(:,2));
  797. RTE.Y_2 = cat(1,RTE.Y_2,R_EPHYS(r).model(m).LFP(i,f).Y(:,2));
  798. RTE.ang_2 = cat(1,RTE.ang_2,R_EPHYS(r).model(m).LFP(i,f).ang(:,2));
  799. RTE.ecc_2 = cat(1,RTE.ecc_2,R_EPHYS(r).model(m).LFP(i,f).ecc(:,2));
  800. %--
  801. RTE.dXY = cat(1,RTE.dXY,R_EPHYS(r).model(m).LFP(i,f).diff.XY);
  802. RTE.dRFS = cat(1,RTE.dRFS,R_EPHYS(r).model(m).LFP(i,f).diff.rfs);
  803. %--
  804. % optional fields
  805. if isfield(R_EPHYS(r).model(m).LFP,'R2')
  806. RTE.R2_1 = cat(1,RTE.R2_1,R_EPHYS(r).model(m).LFP(i,f).R2(:,1));
  807. RTE.R2_2 = cat(1,RTE.R2_2,R_EPHYS(r).model(m).LFP(i,f).R2(:,2));
  808. else
  809. RTE.R2_1 = cat(1,RTE.R2_1,nan(nChan,1));
  810. RTE.R2_2 = cat(1,RTE.R2_2,nan(nChan,1));
  811. end
  812. if isfield(R_EPHYS(r).model(m).LFP,'gain')
  813. RTE.gain_1 = cat(1,RTE.gain_1,R_EPHYS(r).model(m).LFP(i,f).gain(:,1));
  814. RTE.gain_2 = cat(1,RTE.gain_2,R_EPHYS(r).model(m).LFP(i,f).gain(:,2));
  815. else
  816. RTE.gain_1 = cat(1,RTE.gain_1,nan(nChan,1));
  817. RTE.gain_2 = cat(1,RTE.gain_2,nan(nChan,1));
  818. end
  819. if isfield(R_EPHYS(r).model(m).LFP,'expt')
  820. RTE.expt_1 = cat(1,RTE.expt_1,R_EPHYS(r).model(m).LFP(i,f).expt(:,1));
  821. RTE.expt_2 = cat(1,RTE.expt_2,R_EPHYS(r).model(m).LFP(i,f).expt(:,2));
  822. else
  823. RTE.expt_1 = cat(1,RTE.expt_1,nan(nChan,1));
  824. RTE.expt_2 = cat(1,RTE.expt_2,nan(nChan,1));
  825. end
  826. if isfield(R_EPHYS(r).model(m).LFP,'sdratio')
  827. RTE.sdratio_1 = cat(1,RTE.sdratio_1,R_EPHYS(r).model(m).LFP(i,f).sdratio(:,1));
  828. RTE.sdratio_2 = cat(1,RTE.sdratio_2,R_EPHYS(r).model(m).LFP(i,f).sdratio(:,2));
  829. else
  830. RTE.sdratio_1 = cat(1,RTE.sdratio_1,nan(nChan,1));
  831. RTE.sdratio_2 = cat(1,RTE.sdratio_2,nan(nChan,1));
  832. end
  833. if isfield(R_EPHYS(r).model(m).LFP,'normamp')
  834. RTE.normamp_1 = cat(1,RTE.normamp_1,R_EPHYS(r).model(m).LFP(i,f).normamp(:,1));
  835. RTE.normamp_2 = cat(1,RTE.normamp_2,R_EPHYS(r).model(m).LFP(i,f).normamp(:,2));
  836. else
  837. RTE.normamp_1 = cat(1,RTE.normamp_1,nan(nChan,1));
  838. RTE.normamp_2 = cat(1,RTE.normamp_2,nan(nChan,1));
  839. end
  840. if isfield(R_EPHYS(r).model(m).LFP,'SNR')
  841. RTE.SNR = cat(1,RTE.SNR,R_EPHYS(r).model(m).LFP(i,f).SNR);
  842. else
  843. RTE.SNR = cat(1,RTE.SNR,nan(nChan,1));
  844. end
  845. end
  846. end
  847. end
  848. end
  849. RTE.Monkey = RTEm.Monkey;
  850. RTE.Mode = RTEm.Mode;
  851. RTE.Model = RTEm.Model;
  852. RTE.SigType = RTEm.SigType;
  853. RTE.Array = RTEm.Array;
  854. RTE.Chan = RTEm.Chan;
  855. RTE.Area = RTEm.Area;
  856. tLFP = struct2table(RTE);
  857. tLFP_mean = struct2table(RTEm);
  858. LFP.RTE = RTE;
  859. LFP.RTEm = RTEm;
  860. %% SAVE the tables & structs ==============================================
  861. fprintf('\n==============================\n')
  862. fprintf('Saving the results\n')
  863. fprintf('==============================\n')
  864. fprintf('Tables...\n');
  865. % save(...
  866. % fullfile(output_path,'Tables_diff'),...
  867. % 'tMRI','tMUA','tLFP','-v7.3');
  868. save(...
  869. fullfile(output_path,'Tables_mean'),...
  870. 'tMRI_mean','tMUA_mean','tLFP_mean','-v7.3');
  871. % fprintf('Structures...\n');
  872. % save(...
  873. % fullfile(output_path,'MRI_Struct'),'MRI','-v7.3');
  874. % save(...
  875. % fullfile(output_path,'MUA_Struct'),'MUA','-v7.3');
  876. % save(...
  877. % fullfile(output_path,'LFP_Struct'),'LFP','-v7.3');
  878. fprintf('\nALL DONE!\n');