C++ call matlab on (mac + xcode )(二)

2014-11-24 07:22:00 · 作者: · 浏览: 1
t = NULL; char buffer[BUFSIZE+1]; double time[10] = { 0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0 }; /* * Call engOpen with a NULL string. This starts a MATLAB process * on the current host using the command matlab. */ if (!(ep = engOpen())) { fprintf(stderr, Can't start MATLAB engine ); return EXIT_FAILURE; } T = mxCreateDoubleMatrix(1, 10,mxREAL); //transform double to mxArray(double of C++转mxArray) memcpy((void *)mxGetPr(T), (void *)time, sizeof(time)); engPutVariable(ep, T, T);//传入matlab //transform mxArray to double(mxArray转double) memcpy((void*)time, (void*)mxGetPr(T), sizeof(mxGetPr(T))*10);//注意要乘以time的长度 buffer[BUFSIZE] = ''; engOutputBuffer(ep, buffer, BUFSIZE); engeva lString(ep, D = kmeans(T,3)); mxDestroyArray(T); mxDestroyArray(result); return EXIT_SUCCESS; }





-------------------------------------------- 4. 利用XCode进行Exception精确定位



最后再说一个xcode调试的小技巧,如何更精确定位错误。调试的时候有时会报出很多奇葩的错误,看了也不知道哪里出错,这时xcode可以定断点为出错位置:

/