問題描述
我有一個 MEX 文件,我從其他人那里借用"了它來幫助我編寫半自動核檢測算法.問題是 MEX 文件偶爾會導致分段錯誤.但是,如果第二次使用相同的參數運行代碼,那就沒問題了.
I have a MEX file which I "borrowed" from someone else to help me code a semi-automated nuclear detection algorithm. The problem is that the MEX file sporadically causes a segmentation fault. However, if the code is run with the same parameters a second time, it's fine.
我希望有一種用于 MEX 文件的 try/catch
習慣用法,但是在我星期六的大部分時間都在尋找某些東西之后,我什么也沒找到.
I was hoping there was a sort of try/catch
idiom for MEX files, but after spending most of my Saturday looking for something, I couldn't find anything.
對這個問題的任何幫助都會很棒!否則,我將不得不將 .cpp
移植到 MATLAB(它大約有 10,000 行,使用數百個依賴項 :-().
Any help on this issue would be amazing! Otherwise, I am going to have to port the .cpp
into MATLAB (and it's around 10,000 lines using hundreds of dependencies :-().
推薦答案
您使用的是哪個平臺?有一些方法可以幫助調試您的 MEX 文件.每當出現分段錯誤時,您都可以使用 IDE 來告訴您它在代碼中崩潰的位置.
Which platform are you using? There are methods to help debug your MEX files. Whenever there is a segmentation fault, you can use an IDE to tell you where in the code it's crashing.
Mac OS 的說明如下:http://www.mathworks.com/help/matlab/matlab_external/debugging-on-mac-platforms.html
Here are the directions for Mac OS: http://www.mathworks.com/help/matlab/matlab_external/debugging-on-mac-platforms.html
以下是 Linux 的說明:http://www.mathworks.com/help/matlab/matlab_external/debugging-on-linux-platforms.html
Here are the directions for Linux: http://www.mathworks.com/help/matlab/matlab_external/debugging-on-linux-platforms.html
以下是 Windows 的說明:http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html
Here are the directions for Windows: http://www.mathworks.com/help/matlab/matlab_external/debugging-on-microsoft-windows-platforms.html
注意:我反對將 OP 引向場外鏈接以幫助解決他或她的問題.我通常在我的帖子中包含大部分答案,并提供鏈接作為參考.因為您沒有告訴我您使用的是什么平臺,所以我不會為所有平臺編寫解決方案,因為這會花費太多時間.因此(我祈禱鏈接能長期穩定),您可以參考適合您平臺的鏈接.
NB: I am against 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.
這篇關于防止 MEX 文件在 MATLAB 中崩潰的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!