Using the C Math Library    

Replacing Argument Lists with a Cell Array

In MATLAB you can substitute a cell array for a comma-separated list of MATLAB variables when you pass input arguments to a function. MATLAB treats the contents of each cell as a separate input argument. To trigger this functionality, you specify multiple values by indexing into the cell array with, for example, the colon index or a vector index.

For example, the MATLAB expression

when passed as an input argument is equivalent to a comma-separated list of the contents of the first five cells of T. Simply passing the cell array T produces an error.

The MATLAB C Math Library also supports the expansion of the contents of a cell array into separate input arguments for library functions. For functions that implement MATLAB varargin functions, you use the indexing function mlfIndexRef() and a cell array index to obtain an array reference that returns multiple values.

For example, given the varargin function

you can make the following call:

A and B, pointers to existing mxArrays, are passed as explicit arguments. C is a pointer to a cell array that contains at least five cells. The embedded call to mlfIndexRef() uses the index {1:5} to return multiple values: the first five cells of C. The MATLAB C Math Library passes these as individual arguments to mlfVarargin_Func().

Positioning the Indexed Cell Array

See Cell Array Indexing to learn more about indexing into cell arrays.

Exception for Built-In Library Functions

For built-in MATLAB C Math Library functions that are varargin functions, for example, mlfCat(), mlfRand(), and mlfOnes()), consider the explicit argument that immediately precedes the ... as part of the varargin arguments. This argument can accept an indexed cell array expression.

For example, in this code the embedded call to mlfIndexRef() is in the position of the explicit argument that precedes the ... in the signature of the built-in function mlfCat().


 Example - Passing Functions As Arguments (ex4.c) Importing and Exporting Array Data