防止 MEX 文件在 MATLAB 中崩溃

Preventing a MEX file from crashing in MATLAB(防止 MEX 文件在 MATLAB 中崩溃)

本文介绍了防止 MEX 文件在 MATLAB 中崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 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 中崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:防止 MEX 文件在 MATLAB 中崩溃

基础教程推荐