MATLAB: Nargout of builtin set

nargoutset

The function set() returns either zero output (when 3 arguments are supplied), either 1 output (when 1 argument is supplied). Hence I thought nargout(@set) was negative, since a variable number of outputs is supposed to rely on the varargout mechanism. However, nargout(@set)= 1 !
I don't understand. How can Matlab supply a function with varying number of outputs that does not use varargout ? Is it a bug in nargout ?
Thank you

Best Answer

Varying number of outputs do not need to rely on varargout. It is completely legal to have something like
function r = set(h, varargin)
....
tr = ....
if nargout > 0; r = tr; end
end
varargout is used for arguments that are not named in the output list; ndgrid() is an example where it does not make sense to have the function code name arguments.
Related Question