Skip to content

Instantly share code, notes, and snippets.

@MarcelTh
Forked from hagenw/narginchk.m
Last active December 28, 2015 17:39
Show Gist options
  • Save MarcelTh/7537164 to your computer and use it in GitHub Desktop.
Save MarcelTh/7537164 to your computer and use it in GitHub Desktop.
function narginchk(minargs, maxargs)
if (nargin ~= 2)
error('%s: Usage: narginchk(minargs, maxargs)',upper(mfilename));
elseif (~isnumeric (minargs) || ~isscalar (minargs))
error ('minargs must be a numeric scalar');
elseif (~isnumeric (maxargs) || ~isscalar (maxargs))
error ('maxargs must be a numeric scalar');
elseif (minargs > maxargs)
error ('minargs cannot be larger than maxargs')
end
args = evalin ('caller', 'nargin;');
if (args < minargs)
error ('not enough input arguments');
elseif (args > maxargs)
error ('too many input arguments');
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment