C Math Library Reference | ![]() ![]() |
Generate the last index for an array dimension
C Prototype
mxArray *mlfEnd(mxArray *array, mxArray *dim, mxArray *numindices);
Arguments
mxArray *array
Specifies the target array.
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
.
/* In MATLAB: A(5,21:end,4) */ mlfAssign(&index, mlfColon(mlfScalar(1), mlfEnd(C, mlfScalar(2),mlfScalar(3)), NULL)); mlfAssign(&D, mlfIndexRef(C, "(?,?,?)", /* Three dimension index */ mlfScalar(5), /* Row */ index, /* Column */ mlfScalar(4))); /* Page */
See Also
mlfIndexAssign
, mlfIndexDelete
, mlfIndexRef
, mlfColon
, mlfCreateColonIndex
![]() | mlfDoubleMatrix | mlfEnterNewContext | ![]() |