C Math Library Reference    
mlfEnd

Generate the last index for an array dimension

C Prototype

Arguments
mxArray *array
   Specifies the target array.

mxArray *dim
   Dimension in the target array for which the last index is determined.

mxArray *numindices
   Total number of dimensions; that is, the total number of indices in the indexing subscript.

Description

The mlfEnd() function, which corresponds to the MATLAB end() function, provides another way of specifying a vector index. Given an array, a dimension (1 = row, 2 = column, 3 = page, etc.), and the number of indices in the subscript, mlfEnd() returns the index of the last element in the specified dimension. You can then use that scalar array to generate a vector index to be used in one or two-dimensional indexing.

Given the row dimension, mlfEnd() returns the number of columns. Given the column dimension, it returns the number of rows. For a matrix and a one-dimensional index, mlfEnd() treats the matrix like a vector and returns the number of elements in the matrix. The number of indices in the subscript corresponds to the number of index arguments you pass to mlfArrayRef().

Example

This example extracts the elements in row five of page four in this three-dimensional array. The example first uses mlfColon() to create a vector of all the indices along the second dimension. The first argument to mlfColon() indicates the vector should start with 1. The second argument is a nested call to mlfEnd(), which defines the end value of the vector. The arguments to mlfEnd() indicate that the target array is C, the dimension being measured is the second dimension, and the total number of subscripts in the index is 3.

See Also

mlfIndexAssign, mlfIndexDelete, mlfIndexRef, mlfColon, mlfCreateColonIndex


 mlfDoubleMatrix mlfEnterNewContext