nargin means "number of arguments in". In the above code it looks pretty useless:
nargin in this case can only be 0 or 1, since yatzy(n) only allows for one input argument, (n), or no input arguments, yatzy. If you call yatzy with two input arguments, e.g.
It will error out with something along the lines of "Error using yatzy, more input arguments than expected"
Now as for future reference, since you're learning: nargin is typically used for error checking and so you can have optional arguments, e.g:
let's write a program f that takes one or two input arguments with the 2nd being optional:
function out = f(x,y);
if nargin==0
error('Not enough input arguments, 1 is required');
elseif nargin==1
y = pi;
end
Here we've made sure the person enters at least one argument, x, if they entered a second one great! if not, the second one, y, = pi.
Good luck!
Best Answer