Can I pass a C or shared library function to FMINSEARCH, FZERO or other function with takes an MATLAB function handle as input?

1 view (last 30 days)
I would like to pass a C or shared library function to a function such as FMINSEARCH, which expects an MATLAB function handle as input and iteratively finds a minimum of the function.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 22 Jan 2010
You can use your C or shared library function in the folowing manner:
If you are using a C function, first call this function from a MEX-file, and then call the MEX-file from an MATLAB function. Pass the handle to the wrapper MATLAB function to FMINSEARCH.
For more information about the process of compiling and calling a simple MEX file from MATLAB, see the documentation chapter on "Creating C Language MEX-Files".
If you are using a shared library (DLL) function, write an MATLAB function which uses the LOADLIBRARY and CALLLIB commands to call your shared library function. You can then pass a handle to this wrapper MATLAB function to FMINSEARCH.
For more information, see the documentation chapter on "MATLAB Interface to Generic DLLs".
For information about using C or shared library functions with FMINSEARCH or other MATLAB function which takes an MATLAB function handle as input, please see the Related Solution below.

More Answers (0)

Categories

Find more on File Operations in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!