2014-03-07 41 views
0

我有C++代碼,它使用MATLAB引擎調用MATLAB函數。C++從Matlab引擎獲得雙數組

MATLAB函數結果是一個3雙打的數組。

如何將該陣列返回爲C++作爲雙數組?

+0

雙yourArray [3] = fMatlabFunction();你可以直接用C++調用matlab函數(包裝或其他)嗎? – CoryKramer

+0

我使用engEvalString調用matlab函數 – user2824393

回答

2

可以使用:

// e.g. array_name=[1 2 3] in MATLAB 
Engine * matlab; 
... 
mxArray * m = engGetVariable(matlab, "array_name"); 
double * ptr = (double *) mxGetData(m); // ptr is the double array you need 

// you can skip the following if you don't use OpenCV 
Mat mat(3, 1, CV_64F); // CV_64F <=> double 
memcpy(mat.ptr(), ptr, 3*sizeof(double)); 
+0

謝謝我的朋友 – user2824393