Matlab
1 #include "stdio.h" 2 #include "stdlib.h" 3 #include "string.h" 4 #include "math.h" 5 #include "engine.h" 6 7 void main() 8 { 9 int i(0),j(0); 10 Engine *ep; //定义Matlab引擎指针。 11 if (!(ep=engOpen(NULL))) //测试是否启动Matlab引擎成功。 12 { 13 printf("Can't start Matlab engine!" ); 14 exit(1); 15 } 16 engEvalString(ep,"cd E:\\bs\\data\\m_data;"); 17 engEvalString(ep,"load data03.txt"); 18 mxArray * mx_data03; 19 mx_data03=mxCreateDoubleMatrix(31,8,mxREAL); 20 mx_data03=engGetVariable(ep,"data03"); 21 22 double ** data03; 23 data03=(double **)malloc(31*sizeof(double)); 24 for(i=0;i<31;i++) 25 data03[i]=(double *)malloc(8*sizeof(double)); 26 // memcpy(data03,mxGetPr(mx_data03),31*8*sizeof(double)); 27 double * p; 28 p=mxGetPr(mx_data03); 29 30 for( j=0;j<8;j++) 31 { 32 for(i=0;i<31;i++) 33 { 35 data03[i][j]=*p; 36 p++; 38 } 39 } 41 for(i=0;i<31;i++) 42 { 43 for( j=0;j<8;j++) 44 { 45 printf("%f\t",data03[i][j]); 46 } 47 printf("\n"); 48 } 49 }