function fitnonlinearmodel_consolidate(dir0) <dir0> is a directory containing results from fitnonlinearmodel.m load in all of the *.mat files in <dir0> and write the consolidated results to <dir0>.mat. we assume that the full set of voxels have been analyzed (in one or more chunks). only the primary outputs of fitnonlinearmodel.m are saved to the new file; the auxiliary outputs (that exist in individual .mat files) are not. note that we check to make sure that the total number of voxels that are found in the .mat files is equal to the total number of voxels specified in the original call to fitnonlinearmodel.m. this ensures that all voxels have been analyzed! example: % first, set up the problem x = randn(100,1); y = bsxfun(@plus,2*x + 3,randn(100,20)); opt = struct( ... 'outputdir','test', ... 'stimulus',[x ones(100,1)], ... 'data',y, ... 'model',{{[1 1] [-Inf -Inf; Inf Inf] @(pp,dd) dd*pp'}}); % next, do the fitting in chunks of 2 for p=1:10 fitnonlinearmodel(opt,2,p); end % then, consolidate the results fitnonlinearmodel_consolidate('test'); % check the output a = load('test.mat'); a
0001 function fitnonlinearmodel_consolidate(dir0) 0002 0003 % function fitnonlinearmodel_consolidate(dir0) 0004 % 0005 % <dir0> is a directory containing results from fitnonlinearmodel.m 0006 % 0007 % load in all of the *.mat files in <dir0> and write 0008 % the consolidated results to <dir0>.mat. 0009 % 0010 % we assume that the full set of voxels have been analyzed 0011 % (in one or more chunks). only the primary outputs of 0012 % fitnonlinearmodel.m are saved to the new file; the auxiliary 0013 % outputs (that exist in individual .mat files) are not. 0014 % 0015 % note that we check to make sure that the total number of 0016 % voxels that are found in the .mat files is equal to the total 0017 % number of voxels specified in the original call to fitnonlinearmodel.m. 0018 % this ensures that all voxels have been analyzed! 0019 % 0020 % example: 0021 % 0022 % % first, set up the problem 0023 % x = randn(100,1); 0024 % y = bsxfun(@plus,2*x + 3,randn(100,20)); 0025 % opt = struct( ... 0026 % 'outputdir','test', ... 0027 % 'stimulus',[x ones(100,1)], ... 0028 % 'data',y, ... 0029 % 'model',{{[1 1] [-Inf -Inf; Inf Inf] @(pp,dd) dd*pp'}}); 0030 % 0031 % % next, do the fitting in chunks of 2 0032 % for p=1:10 0033 % fitnonlinearmodel(opt,2,p); 0034 % end 0035 % 0036 % % then, consolidate the results 0037 % fitnonlinearmodel_consolidate('test'); 0038 % 0039 % % check the output 0040 % a = load('test.mat'); 0041 % a 0042 0043 % consolidate 0044 file0 = consolidatematdir(dir0,{'opt'}); % 'opt' may be big. let's specifically exclude it. 0045 0046 % load 0047 a = load(file0); 0048 0049 % what is the total number of voxels (so we can check) 0050 totalnumvxs = a.results(1).totalnumvxs; 0051 0052 % assign to b, consolidating as we go 0053 clear b; 0054 varlist = {'params' 'trainperformance' 'testperformance' 'aggregatedtestperformance' 'testdata' 'modelpred' 'modelfit' 'numiters' 'resnorms'}; 0055 dimlist = [3 2 2 2 2 2 3 2 2]; 0056 for zz=1:length(varlist) 0057 if isfield(a.results(1),varlist{zz}); 0058 0059 % cat the results 0060 temp = cat(dimlist(zz),a.results.(varlist{zz})); 0061 0062 % check if we have the full set of results. note that sometimes outputs can be empty. 0063 assert(isempty(temp) || size(temp,dimlist(zz)) == totalnumvxs, ... 0064 'we did not find the full set of results!'); 0065 0066 % record 0067 b.(varlist{zz}) = temp; 0068 0069 end 0070 end 0071 0072 % save 0073 save(file0,'-struct','b');