External Interfaces/API Reference |
Return the offset (index) from the first element to the desired element
Fortran Syntax
Arguments
nsubs
The number of elements in the subs
array. Typically, you set nsubs
equal to the number of dimensions in the mxArray
that pm
points to.
subs
An array of integers. Each value in the array should specify that dimension's subscript. The value in subs(1)
specifies the row subscript, and the value in subs(2)
specifies the column subscript. Use 1-based indexing to specify the desired array element. For example, to express the starting element of a two-dimensional mxArray
in subs
, set subs(1)
to 1 and subs(2)
to 1
.
Returns
The number of elements between the start of the mxArray
and the specified subscript. This returned number is called an "index"; many mx
routines (for example, mxGetField
) require an index as an argument.
If subs
describes the starting element of an mxArray
, mxCalcSingleSubscript
returns 0. If subs
describes the final element of an mxArray
, then mxCalcSingleSubscript
returns N-1
(where N
is the total number of elements).
Description
Call mxCalcSingleSubscript
to determine how many elements there are between the beginning of the mxArray
and a given element of that mxArray
. For example, given a subscript like (5,7)
, mxCalcSingleSubscript
returns the distance from the (1,1)
element of the array to the (5,7)
element. Remember that the mxArray
data type internally represents all data elements in a one-dimensional array no matter how many dimensions the MATLAB mxArray
appears to have.
Use mxCalcSingleSubscript
with functions that interact with multidimensional cells and structures. mxGetCell
and mxSetCell
are two such functions.
See Also
mxAddField | mxCalloc |