語法
nargout
nargout(fun)
相關:varargout、nargin、varargin
套用舉例
function varargout = foo(varargin)
fprintf('How many output arguments? %d\n', nargout);
for k=1:nargout
varargout(k) = {varargin{k}};
end
end
輸出結果
>> ret = foo(1, 2, 3)
How many output arguments? 1
ret = 1
>> [retA, retB] = foo(1, 2, 3)
How many output arguments? 2
retA = 1
retB = 2
>> [retA, retB, retC] = foo(1, 2, 3)
How many output arguments? 3
retA = 1
retB = 2
retC = 3