【VC开源代码栏目提醒】:网学会员鉴于大家对VC开源代码十分关注,论文会员在此为大家搜集整理了“EngineEx.cpp”一文,供大家参考学习
// EngineEx.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "engine.h"
#include "stdio.h"
int main(int argc, char* argv[])
{
Engine *ep = NULL ;//定义引擎
mxArray *T = NULL ;
mxArray *Y = NULL ;
double* pt = NULL ;
double* py = NULL ;
if ( ! (ep = engOpen("\0")))
{
printf("不能打开 matlab 引擎\n") ;
exit(-1) ;
}
else
printf("成功打开MATLAB引擎\n") ;
////////////////////////
engEvalString(ep, "[T,Y]=ode45('myfun',[0 5],[0 1 1])") ;
T = engGetArray(ep,"T") ;
Y = engGetArray(ep, "Y") ;
int M = mxGetM(T) ;
int N = mxGetN(Y) ;
pt = (double*)mxGetData(T) ;
py = (double*)mxGetData(Y) ;
printf("time\t\ty1\t\ty2\t\ty3\n") ;
for( int i = 0 ; i < M ; i ++ )
{
double temp = pt[i] ;
printf("%f\t",temp) ;
for(int j = 0 ; j < N ; j ++ )
{
temp = py[ j * M + i ] ;
printf("%f\t",temp) ;
}
printf("\n") ;
}
engEvalString(ep,"plot(T,Y,'o')");
engEvalString(ep,"hold on") ;
engEvalString(ep,"plot(T,Y)");
mxDestroyArray(T) ;//释放内存
mxDestroyArray(Y) ;//释放内存
engClose(ep) ;//关闭引擎
return 0;
}