ARGS is a MATLAB program which demonstrates command line argument retrieval.
In particular, ARGS is a demonstration of the NARGIN function, which counts command line arguments and the VARARGIN function, which allows the user to specify that a routine has a variable number of input arguments.
If a MATLAB function takes input arguments, such as
function value = summer ( alpha, beta )then there are two ways of supplying some or all the argument values when invoking the function.
We can call with commandline arguments:
value = summer or value = summer 2 or value = summer 2 4or with functional arguments:
value = summer ( ) or value = summer ( 2 ) or value = summer ( 2, 4 )as long as the arguments are processed correctly.
In the commandline form, the arguments will be given to the function as character strings, which must be re-interpreted as numbers. A convenient way to allow the user to use either way of invoking the function requires that the function include a check as to the type of value it has been given. For example, to handle ALPHA, we might write
if ( nargin < 1 ) alpha = input ( 'Enter value of alpha: ' ); elseif ( ischar ( alpha ) ) alpha = str2num ( alpha ); end
The computer code and data files made available on this web page are distributed under the GNU LGPL license.
ARGS is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version and a JAVA version and a MATLAB version.
You can go up one level to the MATLAB source codes.