vc与matlab混编之引擎

//直接上一段程序,相信大家能看懂的

#include "stdafx.h"
#include <iostream>
#include "engine.h"
#include "matrix.h"

#include "math.h"

using namespace std;
void main()
{
  Engine *ep;
 if(!(ep=engOpen(NULL))) {
  cout<<"Can not start Matlab"<<endl;
  exit(-1);
 }
 char *buffer = new char[350];
 double test[2] = {2,3};
 mxArray *t = mxCreateDoubleMatrix(1,2, mxREAL); 
 memcpy(mxGetPr(t),test,2*sizeof(double));

engPutVariable(ep, "t",t);
 engEvalString(ep,"t = t+t");
 t = engGetVariable(ep,"t");
 double* result = mxGetPr(t);
 cout<<result[1]<<endl;
 mxDestroyArray(t); //销毁mxArray数组xx和yy。
 cout <<"Press any key to exit!" <<endl;
 cin.get();
 engClose(ep); //关闭Matlab引擎。

}

你可能感兴趣的:(vc与matlab混编之引擎)