manpagez: man pages & more
info octave
Home | html | info | man
[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

11.9.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

Built-in Function: functions (fcn_handle)

Return a struct containing information about the function handle fcn_handle.

Built-in Function: func2str (fcn_handle)

Return a string containing the name of the function referenced by the function handle fcn_handle.

Built-in Function: str2func (fcn_name)

Return a function handle constructed from the string fcn_name.


© manpagez.com 2000-2017
Individual documents may contain additional copyright information.