<html lang="en"> <head> <title>Inline Functions - Untitled</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="Untitled"> <meta name="generator" content="makeinfo 4.13"> <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="prev" 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"> <a name="Inline-Functions"></a> <p> Previous: <a rel="previous" accesskey="p" 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.3 Inline Functions</h4> <p>An inline function is created from a string containing the function body using the <code>inline</code> function. The following code defines the function f(x) = x^2 + 2. <pre class="example"> f = inline("x^2 + 2"); </pre> <p class="noindent">After this it is possible to evaluate f at any x by writing <code>f(x)</code>. <!-- ov-fcn-inline.cc --> <p><a name="doc_002dinline"></a> <div class="defun"> — Built-in Function: <b>inline</b> (<var>str</var>)<var><a name="index-inline-649"></a></var><br> — Built-in Function: <b>inline</b> (<var>str, arg1, <small class="dots">...</small></var>)<var><a name="index-inline-650"></a></var><br> — Built-in Function: <b>inline</b> (<var>str, n</var>)<var><a name="index-inline-651"></a></var><br> <blockquote><p>Create an inline function from the character string <var>str</var>. If called with a single argument, the arguments of the generated function are extracted from the function itself. The generated function arguments will then be in alphabetical order. It should be noted that i, and j are ignored as arguments due to the ambiguity between their use as a variable or their use as an inbuilt constant. All arguments followed by a parenthesis are considered to be functions. <p>If the second and subsequent arguments are character strings, they are the names of the arguments of the function. <p>If the second argument is an integer <var>n</var>, the arguments are <code>"x"</code>, <code>"P1"</code>, <small class="dots">...</small>, <code>"P</code><var>N</var><code>"</code>. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dargnames.html#doc_002dargnames">argnames</a>, <a href="doc_002dformula.html#doc_002dformula">formula</a>, <a href="doc_002dvectorize.html#doc_002dvectorize">vectorize</a>. </p></blockquote></div> <!-- ov-fcn-inline.cc --> <p><a name="doc_002dargnames"></a> <div class="defun"> — Built-in Function: <b>argnames</b> (<var>fun</var>)<var><a name="index-argnames-652"></a></var><br> <blockquote><p>Return a cell array of character strings containing the names of the arguments of the inline function <var>fun</var>. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dinline.html#doc_002dinline">inline</a>, <a href="doc_002dformula.html#doc_002dformula">formula</a>, <a href="doc_002dvectorize.html#doc_002dvectorize">vectorize</a>. </p></blockquote></div> <!-- ov-fcn-inline.cc --> <p><a name="doc_002dformula"></a> <div class="defun"> — Built-in Function: <b>formula</b> (<var>fun</var>)<var><a name="index-formula-653"></a></var><br> <blockquote><p>Return a character string representing the inline function <var>fun</var>. Note that <code>char (</code><var>fun</var><code>)</code> is equivalent to <code>formula (</code><var>fun</var><code>)</code>. <!-- Texinfo @sp should work but in practice produces ugly results for HTML. --> <!-- A simple blank line produces the correct behavior. --> <!-- @sp 1 --> <p class="noindent"><strong>See also:</strong> <a href="doc_002dargnames.html#doc_002dargnames">argnames</a>, <a href="doc_002dinline.html#doc_002dinline">inline</a>, <a href="doc_002dvectorize.html#doc_002dvectorize">vectorize</a>. </p></blockquote></div> <!-- ov-fcn-inline.cc --> <p><a name="doc_002dvectorize"></a> <div class="defun"> — Built-in Function: <b>vectorize</b> (<var>fun</var>)<var><a name="index-vectorize-654"></a></var><br> <blockquote><p>Create a vectorized version of the inline function <var>fun</var> by replacing all occurrences of <code>*</code>, <code>/</code>, etc., with <code>.*</code>, <code>./</code>, etc. </p></blockquote></div> <!-- ./miscellaneous/symvar.m --> <p><a name="doc_002dsymvar"></a> <div class="defun"> — Function File: <b>symvar</b> (<var>s</var>)<var><a name="index-symvar-655"></a></var><br> <blockquote><p>Identifies the argument names in the function defined by a string. Common constant names such as <code>pi</code>, <code>NaN</code>, <code>Inf</code>, <code>eps</code>, <code>i</code> or <code>j</code> are ignored. The arguments that are found are returned in a cell array of strings. If no variables are found then the returned cell array is empty. </p></blockquote></div> </body></html>