Matlab/SPM Batch Script Help

19 次查看(过去 30 天)
Hi guys, I'm new to Matlab and SPM and would like some help coming up with or editing a short script to shorten the input field for some fMRI images so that batch processing across multiple subjects could be done easily.
matlabbatch{1}.spm.temporal.st.scans = {
{
'C:\face_rep\rawepi\RawEPI\rsM03953_0005_0006.img,1'
'C:\face_rep\rawepi\RawEPI\rsM03953_0005_0007.img,1'
'C:\face_rep\rawepi\RawEPI\rsM03953_0005_0008.img,1'
'C:\face_rep\rawepi\RawEPI\rsM03953_0005_0009.img,1'
.
.
.
'C:\face_rep\rawepi\RawEPI\rsM03953_0005_0300.img,1'
}
}';
matlabbatch{1}.spm.temporal.st.nslices = 24;
An example I was previously given was the use of a for loop which allows the files for each subject to be processed with a simple change of the directories and works well.
cd(imgdir);
imgfiles = ls('r*.img');
for spmimages = 1:size(imgfiles, 1)
matlabbatch{1}.spm.temporal.st.scans(spmimages,:) = {['C:\face_rep\rawepi\RawEPI\' imgfiles(spmimages,:)]};
end
However, when I try to do up the loop from scratch, I am a little unsure about how to define the 'spmimages' and 'matlabbatch' variables from scratch as I get the "Error using ==> horzcat" message so any help there would be greatly appreciated. Thanks!

采纳的回答

Walter Roberson
Walter Roberson 2012-6-22
cd(imgdir);
imgfiles = dir('r*.img');
for spmimages = 1:size(imgfiles, 1)
matlabbatch{1}.spm.temporal.st.scans{spmimages} = fullfile(imgdir, imgfiles(spmimages).name);
end
Or more simply,
cd(imgdir);
imgfiles = dir('r*.img');
matlabbatch{1}.spm.temporal.st.scans = strcat(imgdir, '\', { imgfiles.name });
The above assume you are just constructing the name, not loading data from them.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

产品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by