call C++ from Matalb
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Dear technical support
I want to call a function written in c++ from Matlab, but do not have an idea how to do it.
I wrote a c++ function which is dependent on an open c++ library (Point cloud library (PCL)), and now I need to use this function in Matlab.
I read the example here: https://au.mathworks.com/help/matlab/matlab_external/standalone-example.html
This example looks good, but it does not show how to link another c++ library like PCL, which is what I need.
Another example shows how to call a c function. https://au.mathworks.com/help/matlab/ref/loadlibrary.html
But I don’t know how to make it work for me. Do I need firstly convert my c++ function to a static library and then use the loadlibrary function?
Thank you for your help!
Regards!
Huajian liu
0 Kommentare
Antworten (4)
Vivek
am 2 Okt. 2019
We've introduced this capability in MATLAB starting in R2019a. Please take a look:
0 Kommentare
Walter Roberson
am 15 Jun. 2017
You do not need to use a static library. However, you need to build a C-compatible interface to the library. It is not possible for MATLAB to call into a C++ object member function: it can only call into C++ static functions and static class functions that defined with
extern "C"
It is, however, possible for a call to a static class function to return an opaque pointer to a C++ object as long as it converts it using (void *) and the MATLAB routine does not do any calculation on it.
0 Kommentare
HANS
am 19 Mär. 2018
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Use Prebuilt MATLAB Interface to C++ Library finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!