Using the C Math Library    

Specifying the Index String

You pass an indexing string as the second argument to an indexing function. An indexing string is always surrounded by "". For example, the MATLAB indexing expression A(2,1) is written like this in the MATLAB C Math Library.

"(?,?)" is the indexing string that specifies a two-dimensional index. The question mark, ?, is a placeholder for each index value.

Some more sample indexing strings:

What an Indexing String Specifies

When you specify an indexing string, you provide the following information to the indexing functions:

An indexing string does not specify:

Complex Indexing Expressions

In MATLAB, you can write complicated indexing expressions. For example, this MATLAB expression

combines cell array, standard, and structure indexing. The expression first selects the third element of cell array B; this third element must be an array. From this array it selects the seventh element, which must be a structure with at least one field, named bfield. From that structure it selects the array stored in the bfield field, and then the element at position (2,1) within that array.

In the MATLAB C Math Library, you can specify this entire indexing operation as a single string: "{?}(?).bfield(?,?)". Passing this string to any of the MATLAB C Math Library indexing functions selects that location for reading, writing, or deletion.

In the MATLAB C Math Library, the expression becomes

Nesting Indexing Operations

In MATLAB, you can nest indexing operations; when you do, the results of the inner indexing operation supply the index values for the outer index operation. Because the MATLAB C Math Library represents MATLAB indexing operations with calls to mlfIndexRef(), you can recreate the MATLAB behavior in the library by nesting calls to mlfIndexRef() inside one another.

For example, the MATLAB expression

becomes

The MATLAB expression

becomes


 Specifying the Target Array Specifying the Values for Indices