12.07.2015 Views

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

GNU Octave - Local Sector 7 web page

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 13: Functions and Script Files 95nargout ()Built-in Functionnargout (fcn name)Built-in FunctionWithin a function, return the number of values the caller expects to receive. If calledwith the optional argument fcn name, return the maximum number of values thenamed function can produce, or -1 if the function can produce a variable number ofvalues.For example,f ()will cause nargout to return 0 inside the function f and[s, t] = f ()will cause nargout to return 2 inside the function f.At the top level, nargout is undefined.warn undefined return valuesBuilt-in VariableIf the value of warn_undefined_return_values is nonzero, print a warning if a functiondoes not define all the values in the return list which are expected. The defaultvalue is 1.nargchk (nargin min, nargin max, n)Function FileIf n is in the range nargin min through nargin max inclusive, return the empty matrix.Otherwise, return a message indicating whether n is too large or too small.This is useful for checking to see that the number of arguments supplied to a functionis within an acceptable range.13.3 Variable-length Argument Lists13.4 Variable-length Return Lists13.5 Returning From a FunctionThe body of a user-defined function can contain a return statement. This statementreturns control to the rest of the <strong>Octave</strong> program. It looks like this:returnUnlike the return statement in C, <strong>Octave</strong>’s return statement cannot be used to returna value from a function. Instead, you must assign values to the list of return variables thatare part of the function statement. The return statement simply makes it easier to exita function from a deeply nested loop or conditional statement.Here is an example of a function that checks to see if any elements of a vector are nonzero.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!