(octave.info)Function Handles


Next: Anonymous Functions Up: Function Handles Anonymous Functions Inline Functions
Enter node , (file) or (file)node

11.11.1 Function Handles
------------------------

A function handle is a pointer to another function and is defined with
the syntax

     @FUNCTION-NAME

For example,

     f = @sin;

creates a function handle called ‘f’ that refers to the function ‘sin’.

   Function handles are used to call other functions indirectly, or to
pass a function as an argument to another function like ‘quad’ or
‘fsolve’.  For example:

     f = @sin;
     quad (f, 0, pi)
         ⇒ 2

   You may use ‘feval’ to call a function using function handle, or
simply write the name of the function handle followed by an argument
list.  If there are no arguments, you must use an empty argument list
‘()’.  For example:

     f = @sin;
     feval (f, pi/4)
         ⇒ 0.70711
     f (pi/4)
         ⇒ 0.70711

 -- : is_function_handle (X)
     Return true if X is a function handle.

     See also: Note: isa, Note: typeinfo, Note:
     class, Note: functions.

 -- : S = functions (FCN_HANDLE)
     Return a structure containing information about the function handle
     FCN_HANDLE.

     The structure S always contains these three fields:

     function
          The function name.  For an anonymous function (no name) this
          will be the actual function definition.

     type
          Type of the function.

          anonymous
               The function is anonymous.

          private
               The function is private.

          overloaded
               The function overloads an existing function.

          simple
               The function is a built-in or m-file function.

          subfunction
               The function is a subfunction within an m-file.

     file
          The m-file that will be called to perform the function.  This
          field is empty for anonymous and built-in functions.

     In addition, some function types may return more information in
     additional fields.

     *Warning:* ‘functions’ is provided for debugging purposes only.
     Its behavior may change in the future and programs should not
     depend on any particular output format.

     See also: Note: func2str, *note str2func:
     XREFstr2func.

 -- : func2str (FCN_HANDLE)
     Return a string containing the name of the function referenced by
     the function handle FCN_HANDLE.

     See also: Note: str2func, *note functions:
     XREFfunctions.

 -- : str2func (FCN_NAME)
 -- : str2func (FCN_NAME, "global")
     Return a function handle constructed from the string FCN_NAME.

     If the optional "global" argument is passed, locally visible
     functions are ignored in the lookup.

     See also: Note: func2str, Note: inline,
     Note: functions.


automatically generated by info2www version 1.2.2.9