Matlab/SPM Batch Script Help

조회 수: 19 (최근 30일)
Benjamin
Benjamin 2012년 6월 22일
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.
  댓글 수: 1
Benjamin
Benjamin 2012년 6월 23일
Thanks for the prompt reply, Walter!

댓글을 달려면 로그인하십시오.

추가 답변 (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