https://www.mathworks.com/help/releases/R2018b/matlab/ref/nargout.html

nargout

  • Number of function output arguments

    Syntax

  • nargout

  • nargout(fun)

    Description

  • nargout returns the number of function output arguments specified in the call to the currently executing function. Use this syntax in the body of a function only.

  • nargout([fun](https://www.mathworks.com/help/releases/R2018b/matlab/ref/nargout.html#bsyib3_-1-fun)) returns the number of outputs that appear in the fun function definition. If the function includes varargout in its definition, then nargout returns the negative of the number of outputs. For example, if function myFun declares outputs y, z, and varargout, then nargout('myFun') returns -3.