Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@hagenw
Last active December 17, 2015 16:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save hagenw/5642886 to your computer and use it in GitHub Desktop.
Save hagenw/5642886 to your computer and use it in GitHub Desktop.
narginchk() for Matlab <2011b
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
@MarcelTh
Copy link

Hi Hagen,

thanks for this contribution - it helped me to run some scripts on older MATLAB installations.
I was a bit curious to see "!=" for the 'not equal' checks, as MATLAB syntax requires "~=" (at least in my R2010b version).
Had to change the script accordingly to make it run...

Regards,

Marcel

P.S.: my forked and working for me version here: https://gist.github.com/MarcelTh/7537164

@hagenw
Copy link
Author

hagenw commented Dec 2, 2013

Hi Marcel,

thanks, I corrected it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment