Dear SPMers, I created a function that performs first level analysis and then should save a glass brain using the following code: spm('defaults','fmri'); spm_get_defaults('cmdline',true) spm_jobman('initcfg'); clear matlabbatch matlabbatch{1}.spm.stats.results.spmmat = {fullfile(fullpath_folder,... 'SPM.mat')}; matlabbatch{1}.spm.stats.results.conspec.contrasts = contrast; matlabbatch{1}.spm.stats.results.conspec.threshdesc = mult_cor; matlabbatch{1}.spm.stats.results.conspec.thresh = pthresh; matlabbatch{1}.spm.stats.results.conspec.extent = clust; matlabbatch{1}.spm.stats.results.print = false; spm_jobman('run',matlabbatch); MIP = spm_mip(xSPM.Z,xSPM.XYZmm,xSPM.M); imwrite(MIP,gray(64),'Glass_brain.png','png'); When I run the matlabbatch (not the MIP lines) by pressing F9, a xSPM variable is generated in the workspace and it works like a charm. But when I run it by calling the function that contains it, xSPM is not created (or does not remain in the workspace). Therefore, I am not able to run the MIP line. Any lights on what I should do to make xSPM appear in the workspace after running matlabbatch via function call? Cheers, Raphael -- Raphael F. Casseb Medical Physicist, Ph.D. Student Medical Physics Lab - University of Campinas Contact: +55 19 3521-8246