Using the C Math Library    

How to Call MATLAB Functions  

Some MATLAB functions accept optional input arguments and return multiple output values. Some MATLAB functions can take a varying number of input and output values; these functions are called varargin and varargout functions.

C does not allow routine with the same name to accept different calling sequences nor does it allow a routine to return more than one value.

Thus, to translate MATLAB functions into callable C routines, the MATLAB C Math Library had to establish certain calling conventions. This chapter describes these conventions.

One Output Argument and Only Required Input Arguments

For MATLAB functions that do not have optional input arguments and that return only a single value, the translation to C syntax is direct. For example, in interpreted MATLAB, you invoke the cosine function, cos, like this

where both X and Y are arrays.

Using the MATLAB C Math Library, you invoke cosine in much the same way

where both X and Y are pointers to mxArray structures. Y must be initialized to NULL. mlfAssign() assigns the return value from mlfCos() to Y.


 Calling Library Routines Optional Input Arguments