How to create a MEX file from a C++ function
Mostrar comentarios más antiguos
Hello, I am currently working on a program that integrates C++, MATLAB, and a geochemical program. I am using the C++ code that they provided to act as a pipe between my main code, written in MATLAB and the geochemical program.
As of now, I have not been able to figure out how to compile the pipe, which I want to solely be a standalone function without a main(). I want it to act like any other MATLAB function. It takes in a few variables and then updates their values as it gets more information from the geochemical program.
So far, I have included:
#include "mex.h" #define printf mexPrintf
and
int main() { cout << "hello world" << endl; return 0; }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
if( main() ) mexErrMsgTxt("main returned non-zero value");
}
in my code. Obviously the int main doesn't make too much sense, but without it's presence I don't know what I should include within the void mexFunction.
Any and all suggestions will be greatly appreciated. Thank you in advance!
Respuestas (3)
James Tursa
el 6 de Jul. de 2011
0 votos
Please post the interface to the C++ function you wish to include in the mex function. i.e., specify what the inputs and outputs are.
Ilya
el 7 de Jul. de 2011
Ilya
el 22 de Jul. de 2011
0 votos
Categorías
Más información sobre Write C Functions Callable from MATLAB (MEX Files) en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!