Borrar filtros
Borrar filtros

how to convert spm script to maatlab command codes?

8 visualizaciones (últimos 30 días)
Mariam Alabbad
Mariam Alabbad el 7 de Abr. de 2022
Comentada: Mariam Alabbad el 30 de Oct. de 2023
hello
I have to preprocess about 50 subject in SPM toolbox so I want to convert the SPM script to matlab code so it done automatically insteasd of manually , i tried my best but it not working can you please help
thank you
%-----------------------------------------------------------------------
% Job saved on 28-Mar-2022 11:13:12 by cfg_util (rev $Rev: 7345 $)
% spm SPM - SPM12 (7771)
% cfg_basicio BasicIO - Unknown
%-----------------------------------------------------------------------
% List of open inputs
nrun = 4; % enter the number of runs here
jobfile = {'/Users/RUN1 output/run1_job.m'};
jobs = repmat(jobfile, 1, nrun);
inputs = cell(0, nrun);
for crun = 1:nrun
end
spm('defaults', 'FMRI');
spm_jobman('run', matlabbatch);
% Execute the code specified in the SPM GUI
%%
matlabbatch{1}.spm.spatial.realign.estwrite.data = {
{
'/Users/1_005_fMRI_3_5mmvox_run1_20170119,1'
'/Users/1_006_fMRI_3_5mmvox_run2_20170119,1'
'/Users/1_007_fMRI_3_5mmvox_run3_20170119,1'
'/Users/1_008_fMRI_3_5mmvox_run4_20170119,1'
}
}';
%%
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.sep = 4;
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.fwhm = 5;
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.rtm = 1;
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.interp = 2;
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.wrap = [0 0 0];
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.weight = '';
matlabbatch{1}.spm.spatial.realign.estwrite.roptions.which = [2 1];
matlabbatch{1}.spm.spatial.realign.estwrite.roptions.interp = 4;
matlabbatch{1}.spm.spatial.realign.estwrite.roptions.wrap = [0 0 0];
matlabbatch{1}.spm.spatial.realign.estwrite.roptions.mask = 1;
matlabbatch{1}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
matlabbatch{2}.spm.spatial.normalise.estwrite.subj.vol = {'mean.img,1'};
%%
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.biasreg = 0.0001;
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.biasfwhm = 60;
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.tpm = {'/Users/spm12/tpm/TPM.nii'};
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.affreg = 'mni';
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.reg = [0 0.001 0.5 0.05 0.2];
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.fwhm = 0;
matlabbatch{2}.spm.spatial.normalise.estwrite.eoptions.samp = 3;
matlabbatch{2}.spm.spatial.normalise.estwrite.woptions.bb = [-78 -112 -70
78 76 85];
matlabbatch{2}.spm.spatial.normalise.estwrite.woptions.vox = [2 2 2];
matlabbatch{2}.spm.spatial.normalise.estwrite.woptions.interp = 4;
matlabbatch{2}.spm.spatial.normalise.estwrite.woptions.prefix = 'w';
%%
matlabbatch{3}.spm.spatial.smooth.data = {
'wr.img,1'
};
%%
matlabbatch{3}.spm.spatial.smooth.fwhm = [8 8 8];
matlabbatch{3}.spm.spatial.smooth.dtype = 0;
matlabbatch{3}.spm.spatial.smooth.im = 0;
matlabbatch{3}.spm.spatial.smooth.prefix = 's';

Respuestas (1)

Anurag
Anurag el 25 de Oct. de 2023
Hi Mariam,
I understand that you want to convert your SPM batch script into a MATLAB script, refer to the following code automating the jobs:
% Set the number of runs
nrun = 4;
% Specify the path to the job file
jobfile = '/path_/to_/your_/job_file/run1_job.m';
% Loop through each run
for crun = 1:nrun
% Load the job file for each run
load(jobfile);
% Update the data input for each run
matlabbatch{1}.spm.spatial.realign.estwrite.data = {
{
['/Users/1_00' num2str(5 + crun) '_fMRI_3_5mmvox_run' num2str(crun) '_20170119,1']
% Add paths for the other runs
}
}';
% Execute the processing for this run
spm('defaults', 'FMRI');
spm_jobman('run', matlabbatch);
% Clear matlabbatch to avoid interference with the next run
clear matlabbatch;
end
Hope this helped.
Regards,
Anurag

Etiquetas

Productos


Versión

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by