Matlab crashes while running a mex function with data.
Afficher commentaires plus anciens
I have written a mex function(in C) which takes 2 arrays and a scalar as inputs and after doing some mathematical calculations, it returns a scalar quantity as output. I can compile the corresponding mex function successfully on the MATLAB platform but as soon as I am gonna run it with some input data, its causing a crash to MATLAB. The error log has a heading "Segmentation Violation detected at Mon Apr 25 ..:..:.. 2016". I also tried to debug it in Linux platform using the GNU debugger 'gdb'. It is showing a problem with all the if statements that I have used to verify the number and type of input/output arguments using nrhs,prhs[],nlhs,plhs[]. For example my first statement for checking the number of input arguments is,
if(nrhs!=3)
mexErrMsgTxt("Error..Three inputs required.");
and likewise others for nlhs. The GNU debugger is placing its first breakpoint at the above if statement and if I am commenting it out it is causing a problem with the second if statement and likewise. When I am commenting out all the if statements the mex function is running successfully and also giving me the desired output.
It's been long since I am trying to remove this bug but I am not unable to do so. Can you please help me with the above problem. For your assistance I am also attaching the mexFunction content which is causing the above problem.
Thanks in advance.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Write C Functions Callable from MATLAB (MEX Files) dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!