MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

switch nargin
case 2
result = a + b;
case 1
result = a + a;
otherwise
result = 0;
end


if nargout > 1
absResult = abs(result);
end


Call addme2 with one or two output arguments.


value = addme2(11,-22)


value =
-11


[value,absValue] = addme2(11,-22)


value =
-11


absValue =
11


Functions return outputs in the order they are declared in the function definition.


See Also


nargin | narginchk | nargout | nargoutchk


See Also
Free download pdf