Function handles are much easier to compile than function name strings. Minimizing the mypeaks function, shown as a surface here, is simplified using function handles. The call to the optimization function fminsearch can be combined with the mypeaks function into one file. You create function handles by specifying the name of a function. In that case, the function handle represents the list of all the functions with that name which you could possibly call from the current context.
Some functions take functions as arguments.
It would be convenient to have the call to the optimization solver as well as the objective function all in the same file. This is now possible with function handles. Here is an M-file, minpeaks.m , that contains a function minpeaks and a subfunction mypeaks. Also, no special code needs to be added to solvers such as fminsearch because feval works on function handles. Before function handles, the function mypeaks needed to be in a separate M-file so that it could be called from inside fminsearch.