Using the C++ Math Library    

Representing Input Arguments As 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 mwArray::cell to obtain an array reference that returns multiple values.

For example, given the varargin function

you can make the following call:

A and B, existing mwArrays, are passed as explicit arguments. C is a cell array that contains at least five cells. The embedded call to cell() 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 varargin_func().

Location of the Indexed Cell Array in the Argument List

See Indexing into Cell Arrays in Chapter 4 to learn more about indexing into cell arrays.


 Example Program: Passing Functions As Arguments (ex3.cpp) Using the Mathematical Operators