#include "stdafx.h"
#include "engine.h"
#include "matrix.h"
int main(int argc, char* argv[])
{
Engine *ep;
mxArray *A_ptr;
double *A;
int i,j; A_ptr=mxCreateDoubleMatrix(10,10,mxReal);
mxSetName(A_ptr,"A");
A=mxGetPr(A_ptr);
for(i=0;i<100;i++)
for (j=0;j<10;j++)
{
A[i+10*j]=(j+1)*(j+1)*(i+1)*(i+1);
}
ep=engOpen("D:\MATLAB6p5\bin\matlab");
engPutArray(ep,A_ptr);
engEvalString(ep,"mesh(A);");
engEvalString(ep,"pring picture.eps-deps;");
engClose(ep);
mxDestroyArray(A_ptr);
exit(0);
}
这段代码是在书上抄下来的,去不可以执行出现如下错误:
E:\MyProject\mat1\mat1.cpp(16) : error C2065: 'mxReal' : undeclared identifier
E:\MyProject\mat1\mat1.cpp(17) : warning C4002: too many actual parameters for macro 'mxSetName'
E:\MyProject\mat1\mat1.cpp(17) : error C2065: 'mxSetName_is_obsolete' : undeclared identifier
E:\MyProject\mat1\mat1.cpp(24) : warning C4129: 'M' : unrecognized character escape sequence
E:\MyProject\mat1\mat1.cpp(24) : warning C4129: 'm' : unrecognized character escape sequence
E:\MyProject\mat1\mat1.cpp(25) : warning C4002: too many actual parameters for macro 'engPutArray'
E:\MyProject\mat1\mat1.cpp(25) : error C2065: 'engPutArray_is_obsolete' : undeclared identifier
E:\MyProject\mat1\mat1.cpp(32) : warning C4508: 'main' : function should return a value; 'void' return type assumed
Error executing cl.exe.
请问高手这该怎么去改?我怎么才能调用到matlab的数学函数?

解决方案 »

  1.   

    Use MATLAB in C
    by njustcxy
    Presuppose:
    Use MATLAB in VC6, coding using C or CPP syntax, compiled with ANSI C
    Method:
    1. Tools->Option->Directories:
    a) Include files: Add %matlabdir%\EXTERN\INCLUDE
    b) Library files: Add \EXTERN\LIB\WIN32\MICROSOFT\MSVC60
    2. Project->setting->link->Add libmmfile.lib libmatlb.lib libmat.lib libmx.lib (in such order)
    3. To run the application, copy the two folders “bin” and “toolbox” to %matlabdir%,add the “%matlabdir%\setup\bin\win32” to the enviroment variable path.
    So the files in %matlabdir%\EXTERN\ are very important!
    这是我用英语写的总结,你自己翻译一下,有问题再联系我。