MATLAB: Only accept odd numbered input arguments

functionMATLABmatlab function

I am writing a function and I would like it to only run if the input argument is odd, is there an easy to specifcy that the input must be odd.

Best Answer

nargin counts the number of input arguments for a function.
mod(x,2) returns 1 when x is odd.
if mod(nargin,2)~=1
error('There must be an odd number of inputs.')