I am trying to speeden up my Matlab program by writing a few functions in C++ and using the mex interface to integrate them. I got my results in a vector in c++. I want to transfer it to an array in MATLAB.
I know i should redirect
plhs[0] to the vector
but i am not getting how exactly should I do it.
When I’ve done similar things, I manually marshal the data so that it won’t be freed when the C++ routine is completed. Here’s a basic outline:
If I save this as
test.cppand then open matlab in that directory, I do the following:which is the expected output. Hopefully that is a good starting point – you may want to inline it, but I’m not sure of the benefit. Btw, if you haven’t checked out the matlab mex help, it is a great resource.