中国科学院光电技术研究所 齐 波 董能力
mex批处理文件的调用格式如下:
mex -f msvc60engmatopts.bat *.c
c文件的格式如下:
/* engwindemo.c
* This is a simple program that illustrates how to
call the MATLAB
* Engine functions from a C program for windows */
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <d:\matlab\extern\include\engine.h>
void main()
{
Engine *ep;
/*
* Start the MATLAB engine
*/
if (!(ep = engOpen(NULL))) {
MessageBox ((HWND)NULL, (LPSTR)
“Can't start MATLAB engine", , MB_OK);
exit(-1);
}
engEvalString(ep, “contour(peaks)");
engClose(ep);
}
程序中的黑体部分即为要加入的m文件的位置。
这样就生成了与m文件同名的exe文件,通过VC++中的外部调用函数便很容易实现了对MATLAB的调用。