Main Content

mxCalcSingleSubscript (C)

Offset from first element to desired element

C Syntax

#include "matrix.h" mwIndex mxCalcSingleSubscript(const mxArray *pm, mwSize nsubs, mwIndex *subs);

Description

CallmxCalcSingleSubscriptto determine how many elements there are between the beginning of themxArrayand a given element of thatmxArray. The function converts subscripts to linear indices.

For example, given a subscript like(5,7),mxCalcSingleSubscriptreturns the distance from the first element of the array to the(5,7)element. Remember that themxArraydata type internally represents all data elements in a one-dimensional array no matter how many dimensions the MATLAB®mxArrayappears to have. For examples showing the internal representation, seeData Storage.

Avoid usingmxCalcSingleSubscriptto 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,mxGetDoublesormxGetComplexDoubles.

Input Arguments

expand all

Pointer to anmxArrayarray, specified asconst mxArray*.

Number of elements in the潜艇array, specified asmwSize. Typically, you setnsubsequal to the number of dimensions in themxArraythatpmpoints to.

Array of subscripts, specified asmwIndex. Each value in the array specifies that dimension's subscript. The value in潜艇(1)specifies the row subscript, and the value in潜艇(2)specifies the column subscript. Use 1-based indexing for subscripts. For example, to express the starting element of a two-dimensionalmxArrayin潜艇, set潜艇(1)to1and潜艇(2)to1.

Examples

See these examples inmatlabroot/extern/examples/mx:

Version History

Introduced before R2006a

See Also

|