Call C++ class from Matlab

조회 수: 8 (최근 30일)
Jared
Jared 2012년 12월 10일
답변: Vivek 2019년 10월 2일
Is it possible to call C++ classes from Matlab? When I use loadlibrary to load a DLL into Matlab, I get the following errors:
Warning: The data type 'error' used by function CLASSNAME does not exist.
> In loadlibrary at 421
Warning: The function 'CLASSNAME' was not found in the library
> In loadlibrary at 421
Would creating a MEX file be any different than using loadlibrary?

채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 10일
Only functions which are
extern "C"
can be called from MATLAB. Those routines have no "this", so only static class methods can be directly called. Those routines can create new objects or reference existing objects, but you cannot pass objects in from MATLAB and cannot return objects to MATLAB.

추가 답변 (2개)

Vivek
Vivek 2019년 10월 2일
We've introduced this capability in MATLAB starting in R2019a. Please take a look:

HANS
HANS 2018년 3월 19일
Hi to all :)
I have name.mex function and many .cpp and .h files related to it. name.mex takes only 1xinf vector which is a complex double values inside and output is the same size vector.
I want to call this name.mex within C++. As I know I have to use "int mexCallMATLAB(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[], const char *command_name);"
Please could anybody give a usage example in C++ ? I guess I have to use "ifstream" to load the data vector before I use the function but do I have to define via "mxArray" or ??
Thx, WR

카테고리

Help CenterFile Exchange에서 C Shared Library Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by