Illustration of nested function:
The output arguments are distinct from variables. The scope of an output argument is merely the nested function; and it cannot be used in the outer function. In this illustration, the outbase is used only in the base function; its value, for illustration, could not be printed from the nestedvolume.
If a variable is not used in an outer function, then the variable is also local to the nested function. The earlier illustration has been modified to elaborate these scope rules. In the illustration below, the value of the output argument outbase cannot be used by the function nestedvolume2 (as it is an output argument, not a variable). The variable bvar is also local to the function base as it is never used in the nestedvolume2. On other hand, the cvar is used by nestedvolume2; therefore its scope is the workspace of nestedvolume2-meaning, for illustration, which it can be printed by printstuff.
An illustration of calling this modified function is shown here:
This function computes a volume
outvol is 105.0
cvar is 15.0