## NARGOUT Number of Output Arguments

Section: Functions and Scripts

### Usage

The special variable `nargout` is defined inside of all functions. It indicates how many return values were requested from the function when it was called. FreeMat allows for fewer return values to be requested from a function than were declared, and `nargout` can be used to determine exactly what subset of the functions outputs are required. There is no syntax for the use of `nargout` - it is automatically defined inside the function body.

### Example

Here is a function that is declared to return five values, and that simply prints the value of `nargout` each time it is called.

         nargouttest.m
    function [a1,a2,a3,a4,a5] = nargouttest
      printf('nargout = %d\n',nargout);
      a1 = 1; a2 = 2; a3 = 3; a4 = 4; a5 = 5;

    --> a1 = nargouttest
    nargout = 1

    a1 =

     1

    --> [a1,a2] = nargouttest
    nargout = 2
    a1 =

     1

    a2 =

     2

    --> [a1,a2,a3] = nargouttest
    nargout = 3
    a1 =

     1

    a2 =

     2

    a3 =

     3

    --> [a1,a2,a3,a4,a5] = nargouttest
    nargout = 5
    a1 =

     1

    a2 =

     2

    a3 =

     3

    a4 =

     4

    a5 =

     5