我开始在 matlab 上使用 mex 来构建一个 c 代码,我写了一个非常简单的代码 (main.c) 开始:
#include "stdio.h"
#include "stdlib.h"
#include "mex.h"
void main()
{
mexPrintf("Hello world");
}
当我在 matlab 脚本中键入 mex main.c 时,一切顺利,我收到以下消息:“使用 'gcc' 构建。MEX 已成功完成。”但是我没有看到消息“Hello world”,我也尝试了 printf() 但没有成功,请问有人知道为什么消息没有出现在 matlab 窗口中吗?
预先感谢您的帮助。
-J
最佳答案
就目前而言,您的代码与 Matlab 不兼容。 Matlab 需要为编译程序的“main”函数定义一个特殊的函数。
为了运行你的代码,你需要有这样的东西:
#include "stdio.h"
#include "stdlib.h"
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray*prhs[] )
{
mexPrintf("Hello world\n");
}
假设它位于名为“helloWorld.c”的文件中,您可以在 Matlab 提示符下运行以下命令:
mex helloWorld.c
helloWorld
关于c++ - mexPrintf 消息未显示在 matlab 命令窗口中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45133194/