<p>Which platform are you using? There are methods to help <em>debug</em> your MEX files. Whenever there is a segmentation fault, you can use an IDE to tell you where in the code it's crashing. </p>
<p>Here are the directions for Mac OS: <a href="http://www.mathworks.com/help/matlab/matlab_external/debugging-on-mac-platforms.html" rel="nofollow">http://www.mathworks.com/help/matlab/matlab_external/debugging-on-mac-platforms.html</a> </p>
<p>Here are the directions for Linux: <a href="http://www.mathworks.com/help/matlab/matlab_external/debugging-on-linux-platforms.html" rel="nofollow">http://www.mathworks.com/help/matlab/matlab_external/debugging-on-linux-platforms.html</a></p>
<p>Here are the directions for Windows: <a href="http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html" rel="nofollow">http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html</a></p>
<p><strong>NB:</strong> I am <em>against</em> referring the OP to a link off-site to help with his or her question. I usually include most of the answer in my posts and provide links as references. Because you haven't told me what platform you're using, I will not write solutions for all platforms as that will take too much time. As such (and I'm praying that the links are stable for a long time), you can refer to the appropriate link for your platform.</p>
<p>This tip was originally posted on <a href="http://stackoverflow.com/questions/23714141/Preventing%20a%20MEX%20file%20from%20crashing%20in%20MATLAB/23714301">Stack Overflow</a>.</p>
Get New Tutorials Delivered to Your Inbox
New tutorials will be sent to your Inbox once a week.