Hi Raphael,
1. Save the following code to a file called run_jobs.m located in a directory included in your matlab path or your current working directory. Do not change anything in the code.
function run_jobs (job_dir, job_pattern)
% initialize spm
spm('defaults', 'FMRI');
spm_jobman ('initcfg');
job_dir_listing = dir (fullfile (job_dir, job_pattern));
for i=1:size(job_dir_listing)
spm_jobman ('run', fullfile (job_dir, job_dir_listing(i).name));
end
end
2. Call the function from the matlab command window. Substitute job_dir with the directory where your batch files are stored and job_pattern with a pattern that matches your batch files and nothing else if you run "dir job_pattern" in your job_dir, e.g. '*.mat' if the only files in job_dir that have extension .mat are your batch files. If for example your batch files are called batchjob1.mat batchjob2.mat etc, then job_pattern could be 'batchjob*.mat'. * is the commonly used wildcard character, see e.g. the matlab help for dir.
run_jobs (job_dir, job_pattern)
I hope this helps!
Cheers,
Andreas
>-----Ursprungligt meddelande-----
>Från: SPM (Statistical Parametric Mapping) [mailto:[log in to unmask]] För
>Raphael Underwood
>Skickat: den 11 januari 2015 00:46
>Till: [log in to unmask]
>Ämne: Re: [SPM] SV: [SPM] Running multiple batch files
>
>Hi Andreas,
>
>Thank you for the help, this looks great. I'm afraid I am so new to matlab I will
>need a little follow-up help. I'm not sure which parts of the script to leave
>alone and which parts to replace with my own filenames/directories. I've
>copied the script below with the sections I am not sure what to do with...
>
>Example usage: run_jobs ('directory where my batch files are?', '*.mat')
>
>function run_jobs (directory where my batch files are?, what job pattern?)
> % initialize spm
> spm('defaults', 'FMRI');
> spm_jobman ('initcfg');
>
> job_dir_listing = dir (do I replace fullfile with something? (directory where
>my batch files are?, job pattern?));
>
> for i=1:total number of batch files?(???)
> spm_jobman ('run', fullfile (job_dir, ???(i).name));
> end
>end
>
>Best wishes,
>Raphael
|