Using the C Math Library    

Optional Input Arguments

Some MATLAB functions take optional input arguments. tril, for example, which returns the lower triangular part of a matrix, takes either one input argument or two. The second input argument, k, if present, indicates which diagonal to use as the upper bound; k=0 indicates the main diagonal, and is the default if no k is specified. In interpreted MATLAB you invoke tril either as

or

where L, X, and k are arrays. k is a 1-by-1 array.

Because C does not permit an application to have two functions with the same name, the MATLAB C Math Library version of the tril function always takes two arguments. The second argument is optional. The word "optional" means that the input argument is optional to the working of the function. However, some value must always appear in that argument's position in the parameter list. Therefore, if you do not want to pass the second argument, you must pass NULL in its place.

The two ways to call the MATLAB C Math library version of tril are

and

where L, X, and k are pointers to mxArray structures. L must be initialized to NULL before being passed to the mlfAssign() routine.


 How to Call MATLAB Functions Optional Output Arguments