How do I pass function handles to C++ mex function in MATLAB 7.8 (R2009a)?

12 visualizaciones (últimos 30 días)
I am looking for an example which demonstrates how to pass a function handle to my C++ mex function.

Respuesta aceptada

MathWorks Support Team
MathWorks Support Team el 27 de Jun. de 2009
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.
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.
2) Create the MEX file and pass the arguments
mex simplefunction.cpp
h = @cos;
x =0.6;
y = simplefunction(h,x);

Más respuestas (0)

Categorías

Más información sobre Call C++ from MATLAB en Help Center y File Exchange.

Productos


Versión

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by