Using the C Math Library    

Summary of Library Calling Conventions

Though this section has focused on just a few functions, the principles presented apply to the majority of the functions in the MATLAB C Math Library. In general, a MATLAB C Math Library function call consists of a function name, a set of input arguments, and a set of output arguments. In addition to being classified as input or output, each argument is either required or optional.

The type of an argument determines where it appears in the function argument list. All output arguments appear before any input argument. Within that division, all required arguments appear before any optional arguments. The order, therefore, is: required outputs, optional outputs, varargout or mlfVarargoutList output (a varargout output list), required inputs, optional inputs, and variable-length inputs (varargin arguments).

To map a MATLAB function call to a MATLAB C Math Library function call, follow these steps:

  1. Capitalize the first letter of the MATLAB function name that you want to call, and add the prefix mlf.
  2. Examine the MATLAB syntax for the function.

    Find the MATLAB call with the largest number of arguments. Determine which input and output arguments are required and which are optional.

  1. Make the first output argument the return value from the function.
  2. Pass any other output arguments as the first arguments to the function. If the function accepts any number of output arguments, pass those arguments to mlfVarargout() or mlfIndexVarargout() in the last output argument position.
  3. Pass a NULL argument wherever an optional output argument does not apply to the particular call you're making.
  4. Pass the input arguments to the C function, following the output arguments. If the function accepts any number of input arguments, pass those arguments as the last input arguments.
  5. Pass a NULL argument wherever an optional input argument does not apply to the particular call.

Passing the wrong number of arguments to a function causes compiler errors. Passing NULL in the place of a required argument causes runtime errors.

Exceptions to the Calling Conventions

The mlfLoad(), mlfSave() and mlfFeval() functions do not follow the standard calling conventions for the library. For information about mlfLoad() and mlfSave(), see Chapter 7, Importing and Exporting Array Data.. For information about mlfFeval(), see Passing Functions As Arguments to Library Routines.


 Variable Output Arguments Example - Calling Library Routines (ex3.c)