Mattlabbatch and using an optional variable

3 Ansichten (letzte 30 Tage)
nines
nines am 14 Mär. 2024
Hello,
I am running a batch job using matlabbatch and it works when I have both T1w and T2w as input variables. Now I want to make it so that the code will run just T1w variables. However, I have made the T2w variable run matlabbatch{2} only if the T2w variable exists. However, I am still getting an error the last line of the code, saying that the inputted job is not a valid job. Do you have any suggestions?
Here is the code:
% realign data
matlabbatch{1}.spm.spatial.realign.estwrite.data = {{timeseries}};
matlabbatch{1}.spm.spatial.realign.estwrite.eoptions.quality = 0.9;
matlabbatch{1}.spm.spatial.realign.estwrite.roptions.prefix = 'r';
meta.realign.reference = 'mean';
meta.realign.interpolation = '4th degree B-spline';
% coreg T2w to T1w
if exist('T2w', 'var')
matlabbatch{2}.spm.spatial.coreg.estwrite.ref = {T1w};
matlabbatch{2}.spm.spatial.coreg.estwrite.source = {T2w};
matlabbatch{2}.spm.spatial.coreg.estwrite.other = {''};
matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.cost_fun = 'nmi';
matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.sep = [4 2];
matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
matlabbatch{2}.spm.spatial.coreg.estwrite.eoptions.fwhm = [7 7];
matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.interp = 4;
matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.wrap = [0 0 0];
matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.mask = 0;
matlabbatch{2}.spm.spatial.coreg.estwrite.roptions.prefix = 'r';
end
% segment T1w/rT2w
matlabbatch{3}.spm.spatial.preproc.channel(1).vols = {T1w};
matlabbatch{3}.spm.spatial.preproc.channel(1).biasreg = 0.001;
matlabbatch{3}.spm.spatial.preproc.channel(1).biasfwhm = 60;
% threshold tissue maps at 70% making them binary images
matlabbatch{4}.spm.util.imcalc.input(1) = cfg_dep('Segment: c1 Images', substruct('.','val', '{}',{3}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','tiss', '()',{1}, '.','c', '()',{':'}));
matlabbatch{4}.spm.util.imcalc.output = 'desc-GM_thresh70';
matlabbatch{4}.spm.util.imcalc.outdir = {destination};
matlabbatch{4}.spm.util.imcalc.expression = 'i1>0.7';
matlabbatch{4}.spm.util.imcalc.var = struct('name', {}, 'value', {});
matlabbatch{4}.spm.util.imcalc.options.dmtx = 0;
% coregister T1w to meanEPI and apply to thresholded tissue images
matlabbatch{7}.spm.spatial.coreg.estwrite.ref(1) = cfg_dep('Realign: Estimate & Reslice: Mean Image', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','rmean'));
matlabbatch{7}.spm.spatial.coreg.estwrite.source = {T1w};
matlabbatch{7}.spm.spatial.coreg.estwrite.other(1) = cfg_dep('Image Calculator: ImCalc Computed Image: desc-GM_thresh70', substruct('.','val', '{}',{4}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
matlabbatch{7}.spm.spatial.coreg.estwrite.other(2) = cfg_dep('Image Calculator: ImCalc Computed Image: desc-WM_thresh70', substruct('.','val', '{}',{5}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
matlabbatch{7}.spm.spatial.coreg.estwrite.other(3) = cfg_dep('Image Calculator: ImCalc Computed Image: desc-CSF_thresh70', substruct('.','val', '{}',{6}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','files'));
matlabbatch{7}.spm.spatial.coreg.estwrite.eoptions.cost_fun = 'nmi';
matlabbatch{7}.spm.spatial.coreg.estwrite.eoptions.sep = [4 2];
matlabbatch{7}.spm.spatial.coreg.estwrite.eoptions.tol = [0.02 0.02 0.02 0.001 0.001 0.001 0.01 0.01 0.01 0.001 0.001 0.001];
matlabbatch{7}.spm.spatial.coreg.estwrite.eoptions.fwhm = [7 7];
matlabbatch{7}.spm.spatial.coreg.estwrite.roptions.interp = 4;
matlabbatch{7}.spm.spatial.coreg.estwrite.roptions.wrap = [0 0 0];
matlabbatch{7}.spm.spatial.coreg.estwrite.roptions.mask = 0;
matlabbatch{7}.spm.spatial.coreg.estwrite.roptions.prefix = 'r';
out = spm_jobman('run',matlabbatch);
Here is the error:
No valid job.
out = spm_jobman('run',matlabbatch);

Antworten (0)

Kategorien

Mehr zu MRI finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by