1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<html lang="en">
<head>
<title>Function Handles - Untitled</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Untitled">
<meta name="generator" content="makeinfo 4.11">
<link title="Top" rel="start" href="index.html#Top">
<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">
<link rel="next" href="Anonymous-Functions.html#Anonymous-Functions" title="Anonymous Functions">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<p>
<a name="Function-Handles"></a>
Next: <a rel="next" accesskey="n" href="Anonymous-Functions.html#Anonymous-Functions">Anonymous Functions</a>,
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>
<hr>
</div>
<h4 class="subsection">11.9.1 Function Handles</h4>
<p>A function handle is a pointer to another function and is defined with
the syntax
<pre class="example"> @<var>function-name</var>
</pre>
<p class="noindent">For example
<pre class="example"> f = @sin;
</pre>
<p class="noindent">Creates a function handle called <code>f</code> that refers to the
function <code>sin</code>.
<p>Function handles are used to call other functions indirectly, or to pass
a function as an argument to another function like <code>quad</code> or
<code>fsolve</code>. For example
<pre class="example"> f = @sin;
quad (f, 0, pi)
2
</pre>
<p>You may use <code>feval</code> 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
‘<samp><span class="samp">()</span></samp>’. For example
<pre class="example"> f = @sin;
feval (f, pi/4)
0.70711
f (pi/4)
0.70711
</pre>
<!-- ov-fcn-handle.cc -->
<p><a name="doc_002dfunctions"></a>
<div class="defun">
— Built-in Function: <b>functions</b> (<var>fcn_handle</var>)<var><a name="index-functions-646"></a></var><br>
<blockquote><p>Return a struct containing information about the function handle
<var>fcn_handle</var>.
</p></blockquote></div>
<!-- ov-fcn-handle.cc -->
<p><a name="doc_002dfunc2str"></a>
<div class="defun">
— Built-in Function: <b>func2str</b> (<var>fcn_handle</var>)<var><a name="index-func2str-647"></a></var><br>
<blockquote><p>Return a string containing the name of the function referenced by
the function handle <var>fcn_handle</var>.
</p></blockquote></div>
<!-- ov-fcn-handle.cc -->
<p><a name="doc_002dstr2func"></a>
<div class="defun">
— Built-in Function: <b>str2func</b> (<var>fcn_name</var>)<var><a name="index-str2func-648"></a></var><br>
<blockquote><p>Return a function handle constructed from the string <var>fcn_name</var>.
</p></blockquote></div>
</body></html>
|