% pre-set variables % - studyfolder: folder where the (subject) sub-folders are located % - vtcfpattern: VTC filename pattern % - prtfpattern: PRT filename pattern (this needs to be altered to link % different protocols!) studyfolder = '/Volumes/hms_study/Imaging'; vtcfpattern = '*_run*MNI.vtc'; prtfpattern = '*_run*_hmcollapsed.prt'; % find folders in the study folder subfolders = findfiles(studyfolder, '*', 'dirs=1', 'depth=1'); nsf = numel(subfolders); % create a cell array for VTC and PRT filenames vtcfiles = cell(nsf, 1); prtfiles = cell(nsf, 1); % first pass: lookup files for fc = 1:nsf % look for VTC and PRT files vtcfiles{fc} = findfiles(subfolders{fc}, vtcfpattern); prtfiles{fc} = findfiles(subfolders{fc}, prtfpattern); % ensure that the number is the same if numel(vtcfiles{fc}) ~= numel(prtfiles{fc}) error('Number of found files mismatch.'); end end % as we are sure that the number of files is correct for each subject % we can simply create two large arrays with filenames vtcfiles = cat(1, vtcfiles{:}); prtfiles = cat(1, prtfiles{:}); % NOTE: AT THIS PLACE, IT IS POSSIBLE TO ADD CODE TO EITHER % - CHECK THE INTEGRITY OF FILES % - PERFORM SOME PROCESS WITH THE PRT CONTENT AND RE-SAVE % - ALTER THE VTC DATA AND RE-SAVE % - etc... % iterate over found files for fc = 1:numel(vtcfiles) % load VTC file vtc = xff(vtcfiles{fc}); % link protocol vtc.NrOfLinkedPRTs = 1; vtc.NameOfLinkedPRT = prtfiles{fc}; % save and clear VTC vtc.Save; vtc.ClearObject; end