Question

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 ?

Was it helpful?

Solution

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));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top