我有使用 MATLAB 引擎C++
调用函数的代码。MATLAB
函数结果是一个包含 3 个双精度数的MATLAB
数组。
如何将该数组恢复C++
为双数组?
您可以使用:
// 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));