标签:blog http os 数据 for 2014 art ar
网上的帖子都是如何将VC++数据添加进入MATLAB中,而VC++调用MATLAB中的数据几乎没有,再次记录一点东西吧
配置好编程环境,本文环境为:VS2012+MATLAB2012b。
首先要了解的是Matlab Engine API函数
接下来贴代码和效果:
void test2() { Engine *ep; if (!(ep = engOpen(NULL))) { cout<<"Can't start MATLAB engine"<<endl; //MessageBox ((HWND)NULL,"Can't start MATLAB engine","Matlab Draw",MB_OK); //return 0; } //在MATLAB空间申请y数组并赋值 engEvalString(ep, "y=0:1:511;"); //engine数据类型 mxArray *gistarry1=NULL; //获取MATLAB空间y的指针 gistarry1=engGetVariable(ep,"y"); cout<<endl; //获取y的维数 cout<<mxGetN(gistarry1)<<endl; cout<<mxGetM(gistarry1)<<endl; //获取y的实部指针 double *bb = mxGetPr(gistarry1); //输出数据 for (int i=0;i<mxGetN(gistarry1);i++) for (int j=0;j<mxGetM(gistarry1);j++) { cout<<bb[i]<<" "; if (i%15==0) { cout<<endl; } } //画图 engEvalString(ep, "x=0:0.01:5.11;plot(x,y);"); engEvalString(ep, "title('Matlab Drawing');"); engEvalString(ep, "xlabel('X');"); engEvalString(ep, "ylabel('Y');"); cout<<endl; system("pause"); engClose(ep); // return 0; }运行效果如下图:
小结:1.数据类型要统一
VC++中调用MATLAB中的数据,布布扣,bubuko.com
标签:blog http os 数据 for 2014 art ar
原文地址:http://blog.csdn.net/sunboyiris/article/details/38470013