1

I have C++ code which calls MATLAB function using MATLAB engine.

The MATLAB function result is an array of 3 doubles.

How can I get that array back to C++ as a double array ?

user2824393
  • 639
  • 3
  • 10
  • 19

1 Answers1

3

You can use:

// 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));
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174