mxCalcSingleSubscript (C)
Offset from first element to desired element
C Syntax
#include "matrix.h" mwIndex mxCalcSingleSubscript(const mxArray *pm, mwSize nsubs, mwIndex *subs);
Description
CallmxCalcSingleSubscript
to determine how many elements there are between the beginning of themxArray
and a given element of thatmxArray
. The function converts subscripts to linear indices.
For example, given a subscript like(5,7)
,mxCalcSingleSubscript
returns the distance from the first element of the array to the(5,7)
element. Remember that themxArray
data type internally represents all data elements in a one-dimensional array no matter how many dimensions the MATLAB®mxArray
appears to have. For examples showing the internal representation, seeData Storage.
Avoid usingmxCalcSingleSubscript
to traverse the elements of an array. In C, it is more efficient to find the starting address of the array and then use pointer autoincrementing to access successive elements. For example, to find the starting address of a numerical array, call one of the typed data access functions, for example,mxGetDoubles
ormxGetComplexDoubles
.