[Neuroimaging] wrap Matlab script using MatlabCommand in Nipype

Hao wen hao.freesurfer at hotmail.com
Wed Jun 29 13:37:57 EDT 2016

Hi everyone, I wrap a matlab script, in the matlab function, I didnt define the output, but I will save some output images to a specific folder, and I use the MatlabCommand in Nipype, so here is my NIpype code:

from nipype.interfaces.utility import Function
import nipype.pipeline.engine as pe

def runmatlab(ContrastLinearModel, Format, CSVFilenames, PATH_TO_RECON_ALL_OUTPUTS, a_required_path):
    from nipype.interfaces.matlab import MatlabCommand
    matlab = MatlabCommand()
    matlab.inputs.paths = [a_required_path]# this is the path to add into matlab, addpath
    matlab.inputs.script = """
    NipypeSurfStat('%s', '%s', '%s', '%s')"""%(ContrastLinearModel, Format,
                                 CSVFilenames, PATH_TO_RECON_ALL_OUTPUTS )
    matlab.inputs.mfile = True # this will create a file: pyscript.m , the pyscript.m is the default name
    out = matlab.run()
    return out

a_required_path = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/Group_analysis/SurfStat/Junhao_script/Code/NipypeSurfStat'
#output_dir = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/Group_analysis/SurfStat/Junhao_script/Figures'
PATH_TO_RECON_ALL_OUTPUTS = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/ADNI_60_AD_CN_object_recon_all_output';
CSVFilenames     = '/aramis/dataARAMIS/users/junhao.wen/Data_AD_CN/Group_analysis/SurfStat/Junhao_script/Database/GroupAnalysisDataAramis/60_AD_CN_GROUPT_ANALYSIS.csv';
Format = '%s %s %s %f';
ContrastLinearModel = '1 + Label';

SurfStat = pe.Node(name='SurfStat',
               interface=Function(input_names=['ContrastLinearModel', 'Format', 'CSVFilenames',
                                     'PATH_TO_RECON_ALL_OUTPUTS', 'a_required_path'],
SurfStat.inputs.ContrastLinearModel = ContrastLinearModel
SurfStat.inputs.Format = Format
SurfStat.inputs.CSVFilenames = CSVFilenames
SurfStat.inputs.a_required_path = a_required_path


But I got some error, and I checked my matlab script, it is caused by this line,

save2jpeg(strcat('Figures/', fileName, '/ContrastPositive-TValue.jpg'));

The error from my nipype is :

Standard error:
Segmentation fault (core dumped)

Return code: 139
Interface MatlabCommand failed to run.
Interface Function failed to run.

I googled, they give me this explaination:

1. Very basically, it means your program is trying to access a memory area it is not suposed to.

2. To the current directoy.

3. You need to make sure your program doesn't do 1..

I have been stucked by this for a long time, any advice will be appreciated:)

Good day! Bonne journée!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/neuroimaging/attachments/20160629/375d58ca/attachment.html>

More information about the Neuroimaging mailing list