You can find out where the SPM.mat file thinks the preprocessed volumes are by looking at SPM.xY.P.
If all of the preprocessed volumes are in the same folder, and you want to loop through SPM.mat files, you should be able to just use fileparts on SPM.xY.P{1} to get the original folder, then use spm_changepath to replace all instances of that substring in the structure with your new path.
If the files are split into different folders by run, you can do a second fileparts to get the parent directory.
|