- Check "matlabbatch" Indices: Ensure that "matlabbatch" indices are correctly set up. When "T2w" is not present, "matlabbatch{2}" should not be created, so subsequent indices should be adjusted. This means you need to adjust the indices of "matlabbatch{3}" and onward if "T2w" doesn't exist.
- Use conditional indexing to adjust the indices of "matlabbatch" based on the existence of "T2w".
- Ensure that the dependencies specified with "cfg_dep" are correctly adjusted if the "T2w" step is skipped.
- Setup breakpoints in your code to identify cause of errors by inspecting variable values
Mattlabbatch and using an optional variable
2 次查看(过去 30 天)
显示 更早的评论
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);
0 个评论
回答(1 个)
Samay Sagar
2024-9-20
The error message "No valid job" suggests that there might be an issue with the "matlabbatch" configuration, particularly when the "T2w" variable is not present. Here are some steps you can take to debug and resolve this issue:
For more information about debugging, you can refer the following documentation:
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!