<html lang="en"> <head> <title>Ignoring Arguments - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="Functions-and-Scripts.html#Functions-and-Scripts" title="Functions and Scripts"> <link rel="prev" href="Variable_002dlength-Argument-Lists.html#Variable_002dlength-Argument-Lists" title="Variable-length Argument Lists"> <link rel="next" href="Variable_002dlength-Return-Lists.html#Variable_002dlength-Return-Lists" title="Variable-length Return Lists"> <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="Ignoring-Arguments"></a> <p> Next: <a rel="next" accesskey="n" href="Variable_002dlength-Return-Lists.html#Variable_002dlength-Return-Lists">Variable-length Return Lists</a>, Previous: <a rel="previous" accesskey="p" href="Variable_002dlength-Argument-Lists.html#Variable_002dlength-Argument-Lists">Variable-length Argument Lists</a>, Up: <a rel="up" accesskey="u" href="Functions-and-Scripts.html#Functions-and-Scripts">Functions and Scripts</a> <hr> </div> <h3 class="section">11.4 Ignoring Arguments</h3> <p>In the formal argument list, it is possible to use the dummy placeholder <code>~</code> instead of a name. This indicates that the corresponding argument value should be ignored and not stored to any variable. <pre class="example"> function val = pick2nd (~, arg2) val = arg2; endfunction </pre> <p>The value of <code>nargin</code> is not affected by using this declaration. <p>Return arguments can also be ignored using the same syntax. Functions may take advantage of ignored outputs to reduce the number of calculations performed. To do so, use the <code>isargout</code> function to query whether the output argument is wanted. For example: <pre class="example"> function [out1, out2] = long_function (x, y, z) if (isargout (1)) ## Long calculation ... out1 = result; endif ... endfunction </pre> <!-- isargout src/ov-usr-fcn.cc --> <p><a name="doc_002disargout"></a> <div class="defun"> — Built-in Function: <b>isargout</b> (<var>k</var>)<var><a name="index-isargout-746"></a></var><br> <blockquote><p>Within a function, return a logical value indicating whether the argument <var>k</var> will be assigned on output to a variable. If the result is false, the argument has been ignored during the function call through the use of the tilde (~) special output argument. Functions can use <code>isargout</code> to avoid performing unnecessary calculations for outputs which are unwanted. <p>If <var>k</var> is outside the range <code>1:max(nargout)</code>, the function returns false. <var>k</var> can also be an array, in which case the function works element-by-element and a logical array is returned. At the top level, <code>isargout</code> returns an error. <!-- 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_002dnargout.html#doc_002dnargout">nargout</a>, <a href="doc_002dnargin.html#doc_002dnargin">nargin</a>, <a href="doc_002dvarargin.html#doc_002dvarargin">varargin</a>, <a href="doc_002dvarargout.html#doc_002dvarargout">varargout</a>, <a href="doc_002dnthargout.html#doc_002dnthargout">nthargout</a>. </p></blockquote></div> </body></html>