MATLAB Function Reference | ![]() ![]() |
Validate number of output arguments
Syntax
Description
msg = nargoutchk(low,high,n)
returns an appropriate error message if n
is not between low
and high
. If the number of output arguments is within the specified range, nargoutchk
returns an empty matrix.
Examples
You can use nargoutchk
to determine if an M-file has been called with the correct number of output arguments. This example uses nargout
to return the number of output arguments specified when the function was called. The function is designed to be called with one, two, or three output arguments. If called with no arguments or more than three arguments, nargoutchk returns an error message.
function [s,varargout] = mysize(x) msg = nargoutchk(1,3,nargout); if isempty(msg) nout = max(nargout,1)-1; s = size(x); for k=1:nout, varargout(k) = {s(k)}; end else disp(msg) end
See Also
nargchk
, nargout
, nargin
, varargout
, varargin
![]() | nargin, nargout | nchoosek | ![]() |