Using mexCallMATLAB to instantiate an object ?

Hello,
I'm trying to embed matlab into my C++ code, using the Engine API. I want to instantiate an object of a specific class ("Vector", say), and then inject that into the workspace via engPutVariable.
To instantiate the Vector, I'm trying to use
mxArray *rhs = ...; // argument
mxArray *lhs = 0;
mexCallMATLAB(1, &lhs, 1, &rhs, "Vector");
However, I'm observing a segmentation fault at the mexCallMATLAB call. Does anyone see what I'm doing wrong here ? Is there a better way to construct an instance of a specific Matlab class from C++ ?
Many thanks, Stefan

 채택된 답변

James Tursa
James Tursa 2011년 6월 21일

0 개 추천

You can't use any of the mex___ API functions with the MATLAB Engine, you have to use the eng___ API functions. Since there is no engCallMATLAB function in the API, you can use this substitute instead from the FEX:

댓글 수: 2

James Tursa
James Tursa 2011년 6월 21일
P.S. I hope your object isn't huge because putting and getting variables from the Engine requires a deep copy, and the API gives you *no* direct pointer access to your object properties (don't ask me why).
James Tursa
James Tursa 2011년 6월 21일
I will qualify my previous statement by stating that it *is* possible to have a mex function that opens and calls an Engine. In that case one can use unofficial methods to get pointers to the object properties, but it still does not avoid the deep copy necessary between the mex routine and the Engine.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Kaustubha Govind
Kaustubha Govind 2011년 6월 21일

0 개 추천

Have you tried following the documentation examples? As far as I know, the Engine API requires you to use engEvalString to call into functions. mexCallMATLAB is used only in MEX-functions.

카테고리

도움말 센터File Exchange에서 Call MATLAB from C에 대해 자세히 알아보기

질문:

2011년 6월 21일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by