Integrating some C++ code in a mex file is not hard: The mex file is started at the entry function "mexFunction". In tis function 3 things happen:
- Input arguments comming from Matlab are converted to C++ variables,
- The C++ functions are called,
- The output is converted back to Matlab variables.
For the 1st job, e.g. mxGetPr() gets the pointer to the data of a Matlab double array. mxGetM /mxGetN gets the dimensions of matrices, etc. Check the types of the inputs by mxIsDouble and reject unexpected types, otherwise the C++ part will crash.
The 3rd job uses e.g. mxCreateDoubleMatrix(). This creates a matrix without setting the values. Either copy the results from the C++ part using memcpy, or create the output arrays initially and provide a pointer to the reserved memory directly to the C++ part.
You see, the mexFunction is the gateway between Matlab and C++ only.