From: Jacob Haynes on
Hi,
I am currently trying to use a C++ genetic algorithm I wrote in matlab.
I have been reading and understand fairly well how to create a MEX-file.
The only problem I have currently is that the algorithm uses function pointers in order to get a cost for the funciton, it uses a function pointer, and I don't know how to make this pointer point to a matlab function, if it is possible at all.
From: Jan Simon on
Dear Jacob!

> I am currently trying to use a C++ genetic algorithm I wrote in matlab.
> I have been reading and understand fairly well how to create a MEX-file.
> The only problem I have currently is that the algorithm uses function pointers in order to get a cost for the funciton, it uses a function pointer, and I don't know how to make this pointer point to a matlab function, if it is possible at all.

What exactly do you want to do?
Is the algorithm written in C++ or M?
You can use a function pointer as input of a Mex file, which calls the corresponding function using mexCallMATLAB, 'feval' as function and the function pointer as argument.
This has been described in the newsgroup before.

Good luck, Jan
From: James Tursa on
"Jacob Haynes" <ezupeve_115(a)yopmail.com> wrote in message <huqtgl$qm2$1(a)fred.mathworks.com>...
> Hi,
> I am currently trying to use a C++ genetic algorithm I wrote in matlab.
> I have been reading and understand fairly well how to create a MEX-file.
> The only problem I have currently is that the algorithm uses function pointers in order to get a cost for the funciton, it uses a function pointer, and I don't know how to make this pointer point to a matlab function, if it is possible at all.

Write a C++ function that internally uses mexCallMATLAB to call the MATLAB function.

James Tursa