Function Handles UC Berkeley Fall 2004, E77 http://jagger.me.berkeley.edu/~pack/e77 Copyright 2005, Andy Packard. This work is licensed under the Creative Commons Attribution-ShareAlike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/2.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
Function handles and feval Several Matlab functions solve your problem by repeatedly calling functions that you supply finding zeros of a function (fzero) Integrating a function (trapz, quad) Integrating a differential equation (ode45) minimizing a function (fminbnd, fminsearch) For example, in calling fzero, you must pass a reference-to-the-function (called a function handle) that you want fzero to find the zeros of. Use the @ operator to get the reference. >> shan = @sin; >> class(shan) >> feval(shan,linspace(0,pi,5)) New data type: add to list with double, cell, char, struct. Any function (built-in, mfile, etc)
Function handles and feval General syntax for feval is [out1,out2,…] = feval(FuncH,arg1,arg2,…) function handle Output argument list Input argument list