問(wèn)題描述
我有一個(gè) MEX 文件,我從其他人那里借用"了它來(lái)幫助我編寫(xiě)半自動(dòng)核檢測(cè)算法.問(wèn)題是 MEX 文件偶爾會(huì)導(dǎo)致分段錯(cuò)誤.但是,如果第二次使用相同的參數(shù)運(yùn)行代碼,那就沒(méi)問(wèn)題了.
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
習(xí)慣用法,但是在我星期六的大部分時(shí)間都在尋找某些東西之后,我什么也沒(méi)找到.
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.
對(duì)這個(gè)問(wèn)題的任何幫助都會(huì)很棒!否則,我將不得不將 .cpp
移植到 MATLAB(它大約有 10,000 行,使用數(shù)百個(gè)依賴項(xiàng) :-().
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 :-().
推薦答案
您使用的是哪個(gè)平臺(tái)?有一些方法可以幫助調(diào)試您的 MEX 文件.每當(dāng)出現(xiàn)分段錯(cuò)誤時(shí),您都可以使用 IDE 來(lái)告訴您它在代碼中崩潰的位置.
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 的說(shuō)明如下: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 的說(shuō)明: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 的說(shuō)明: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
注意:我反對(duì)將 OP 引向場(chǎng)外鏈接以幫助解決他或她的問(wèn)題.我通常在我的帖子中包含大部分答案,并提供鏈接作為參考.因?yàn)槟鷽](méi)有告訴我您使用的是什么平臺(tái),所以我不會(huì)為所有平臺(tái)編寫(xiě)解決方案,因?yàn)檫@會(huì)花費(fèi)太多時(shí)間.因此(我祈禱鏈接能長(zhǎng)期穩(wěn)定),您可以參考適合您平臺(tái)的鏈接.
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.
這篇關(guān)于防止 MEX 文件在 MATLAB 中崩潰的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!