Find Number of Function Arguments
This example shows how to determine how many input or output arguments your function
receives using nargin and nargout.Input ArgumentsCreate a function in a file named addme.m that accepts up to two inputs. Identify the
number of inputs with nargin.function c = addme(a,b)switch nargin
case 2
c = a + b;
case 1
c = a + a;
otherwise
c = 0;
endCall addme with one, two, or zero input arguments.addme(42)ans =
84addme(2,4000)ans =
4002addmeans =
0Output ArgumentsCreate a new function in a file named addme2.m that can return one or two outputs (a
result and its absolute value). Identify the number of requested outputs with nargout.function [result,absResult] = addme2(a,b)21 Function Arguments