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

I am looking for an example which demonstrates how to pass a function handle to my C++ mex function.

 Accepted Answer

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);

More Answers (0)

Categories

Products

Release

R2009a

Community Treasure Hunt

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

Start Hunting!