function buildGangliaLibrary(maskdir,saveloc) %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Saves a .mat library after identifying all the ganglia in a directory % Inputs: % - maskdir: location of all the .mat files with the masks % - saveloc: location where to save the library as mat; if filename is % absent from path, the default name will be lib_ganglia % Output: % - savedir: location where the ganglia library will be saved %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% if ~isfile(saveloc) saveloc = fullfile(saveloc,'lib_ganglia.mat'); end A = dir(fullfile(maskdir, '*masks.mat')); if isempty(A) warning('Unable to locate masks in %s', maskdir) end all_masks = {}; for ii=1:length(A) [gangmask, ~] = makeGanglia_search(fullfile(A(ii).folder,A(ii).name)); if isempty(gangmask), continue; end all_masks = [all_masks gangmask]; end gangmask = all_masks; save(saveloc,"gangmask")