3
<title>Function Handles - Untitled</title>
4
<meta http-equiv="Content-Type" content="text/html">
5
<meta name="description" content="Untitled">
6
<meta name="generator" content="makeinfo 4.11">
7
<link title="Top" rel="start" href="index.html#Top">
8
<link rel="up" href="Function-Handles-Inline-Functions-and-Anonymous-Functions.html#Function-Handles-Inline-Functions-and-Anonymous-Functions" title="Function Handles Inline Functions and Anonymous Functions">
9
<link rel="next" href="Anonymous-Functions.html#Anonymous-Functions" title="Anonymous Functions">
10
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
11
<meta http-equiv="Content-Style-Type" content="text/css">
12
<style type="text/css"><!--
13
pre.display { font-family:inherit }
14
pre.format { font-family:inherit }
15
pre.smalldisplay { font-family:inherit; font-size:smaller }
16
pre.smallformat { font-family:inherit; font-size:smaller }
17
pre.smallexample { font-size:smaller }
18
pre.smalllisp { font-size:smaller }
19
span.sc { font-variant:small-caps }
20
span.roman { font-family:serif; font-weight:normal; }
21
span.sansserif { font-family:sans-serif; font-weight:normal; }
27
<a name="Function-Handles"></a>
28
Next: <a rel="next" accesskey="n" href="Anonymous-Functions.html#Anonymous-Functions">Anonymous Functions</a>,
29
Up: <a rel="up" accesskey="u" href="Function-Handles-Inline-Functions-and-Anonymous-Functions.html#Function-Handles-Inline-Functions-and-Anonymous-Functions">Function Handles Inline Functions and Anonymous Functions</a>
33
<h4 class="subsection">11.9.1 Function Handles</h4>
35
<p>A function handle is a pointer to another function and is defined with
38
<pre class="example"> @<var>function-name</var>
40
<p class="noindent">For example
42
<pre class="example"> f = @sin;
44
<p class="noindent">Creates a function handle called <code>f</code> that refers to the
45
function <code>sin</code>.
47
<p>Function handles are used to call other functions indirectly, or to pass
48
a function as an argument to another function like <code>quad</code> or
49
<code>fsolve</code>. For example
51
<pre class="example"> f = @sin;
55
<p>You may use <code>feval</code> to call a function using function handle, or
56
simply write the name of the function handle followed by an argument
57
list. If there are no arguments, you must use an empty argument list
58
‘<samp><span class="samp">()</span></samp>’. For example
60
<pre class="example"> f = @sin;
66
<p><a name="doc_002dfunctions"></a>
69
— Built-in Function: <b>functions</b> (<var>fcn_handle</var>)<var><a name="index-functions-609"></a></var><br>
70
<blockquote><p>Return a struct containing information about the function handle
71
<var>fcn_handle</var>.
72
</p></blockquote></div>
74
<p><a name="doc_002dfunc2str"></a>
77
— Built-in Function: <b>func2str</b> (<var>fcn_handle</var>)<var><a name="index-func2str-610"></a></var><br>
78
<blockquote><p>Return a string containing the name of the function referenced by
79
the function handle <var>fcn_handle</var>.
80
</p></blockquote></div>
82
<p><a name="doc_002dstr2func"></a>
85
— Built-in Function: <b>str2func</b> (<var>fcn_name</var>)<var><a name="index-str2func-611"></a></var><br>
86
<blockquote><p>Return a function handle constructed from the string <var>fcn_name</var>.
87
</p></blockquote></div>