Using a compiled matlab function in my programs.
Mostrar comentarios más antiguos
Hi, I was needing the "pulstran" function when porting my matlab code to C++. So I did compile it with
mcc -l pulstran
And I have now .c, .h, .lib, everything I need. However in the header I have those functions :
bool MW_CALL_CONV pulstranInitialize(void);
void MW_CALL_CONV pulstranTerminate(void);
void MW_CALL_CONV pulstranPrintStackTrace(void);
bool MW_CALL_CONV mlxPulstran(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]);
long MW_CALL_CONV pulstranGetMcrID();
extern LIB_pulstran_C_API bool MW_CALL_CONV mlfPulstran(int nargout, mxArray** y, mxArray* t, mxArray* d, mxArray* func, mxArray* varargin);
So I suppose I must first call Initialize, then Terminate, and that PrintStackTrace and GetMcrId aren't very useful in my case. Here is my call to pulstran (the MATLAB code).
K = pulstran(tab, D, waveform, freq);
Where tab, D, and waveform are arrays. Wich function must I call in my C code ? And are the matlab types compatible with standard C++ vectors ?
Also, another thing, when using compiled matlab code directly to executables, I noticed some veeeeeeeery long initialization (4 / 5 seconds) befor the program actually ran. Here I'm working in a real time scenario (sound synthesis) and I can't afford these. Will they stay when using the API ?
Thanks a lot!
Respuestas (1)
Kaustubha Govind
el 12 de Jul. de 2012
0 votos
I'd recommend looking at the examples in the documentation to understand how you can call your generated shared library from a C/C++ application. You will need to construct mxArrays for your data before passing it into the shared library.
The long initialization time is basically the amount of time it takes to start up the MCR and should be the similar to MATLAB startup time. Some overhead will exist during initialization and termination time. As long as your synthesis happens between initialize/terminate, hopefully, you will not be affected too much.
2 comentarios
Doom Ooseventh
el 13 de Jul. de 2012
Kaustubha Govind
el 13 de Jul. de 2012
Doom: Could you accept my answer if it helps? Thanks!
Categorías
Más información sobre C Shared Library Integration en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!