1

我有使用 MATLAB 引擎C++调用函数的代码。MATLAB

函数结果是一个包含 3 个双精度数的MATLAB数组。

如何将该数组恢复C++为双数组?

4

1 回答 1

3

您可以使用:

// 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));
于 2014-03-07T12:56:48.683 回答