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

10 views (last 30 days)
I am looking for an example which demonstrates how to pass a function handle to my C++ mex function.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 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);

More Answers (0)

Categories

Find more on Write C Functions Callable from MATLAB (MEX Files) in Help Center and File Exchange

Products


Release

R2009a

Community Treasure Hunt

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

Start Hunting!