Is it possible to pass a function handle to C++ functions in the resent version of matlab?

6 vues (au cours des 30 derniers jours)
I am going to purchase library compiler toolbox. And before purchasing it, I want to know the way to use it on the standalone project. When I searched for it, I found "How do I pass a function handle to my MATLAB C++ Math Library functions?". (https://kr.mathworks.com/matlabcentral/answers/100819-how-do-i-pass-a-function-handle-to-my-matlab-c-math-library-functions) In this question, "matlab.hpp" and FEVAL_ENTRY are used. However, in the answer to the question "About Matlab C++ Math Library", I can know that they have not supported anymore in the later version of R14. (https://kr.mathworks.com/matlabcentral/answers/36324-about-matlab-c-math-library) In the recent version of matlab, Is it possible to pass a function handle to C++ functions in the resent version of matlab? Thank you.
  1 commentaire
Dhruvesh Patel
Dhruvesh Patel le 28 Juin 2017
Modifié(e) : Dhruvesh Patel le 28 Juin 2017
The question does not seem to be clear. You wish to buy MATLAB Compiler SDK (Library Compiler App). It is used to generate C/C++ shared library from MATLAB Code.
Do you wish to create a standalone/library from your MATLAB Code or you wish to call a C/C++ function inside MATLAB ?

Connectez-vous pour commenter.

Réponses (1)

Shruthi Mysore Sadashiva
Shruthi Mysore Sadashiva le 3 Août 2017
I understand that you want to pass function handles to your C++ functions. This could be done by using C++ MEX functions. You can pass function handles to your C++ MEX files and then use “ mexCallMatlab ” function in C++ code to execute the function handles using the FEVAL command.
As an example please find the attached “simplefunction.cpp”, which takes two input arguments and returns an output. The types of input arguments are as follows:
a) A function handle
b) A double value
Please follow these steps to run the example:
1) Use the following command to select C++ compiler:
>>mex -setup
Please note that you have to choose one of the supported and compatible C++ compilers for your version of MATLAB. The following document shows how to choose a C++ compiler: https://www.mathworks.com/help/matlab/matlab_external/choose-c-or-c-compilers.html
To know the supported compilers for your version of MATLAB, please check the following document: https://www.mathworks.com/support/compilers.html
2) Create the MEX file and pass the arguments
>>mex simplefunction.cpp
>>h = @cos;
>>x =0.6;
>>y = simplefunction(h,x);
As Druvesh Patel already mentioned in his comment, MATLAB Compiler SDK is used to generate C/C++ shared library from MATLAB Code. But to pass the function handles to your C++ functions, you should use C++ MEX functions.

Catégories

En savoir plus sur MATLAB Compiler dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!