MATLAB Application Program Interface | Search  Help Desk |
mxGetJc | Examples See Also |
Get the jc
array of a sparse matrix
#include "matrix.h" int *mxGetJc(const mxArray *array_ptr);array_ptr
mxArray
.
A pointer to the first element in the jc
array, if successful; otherwise, returns NULL
. The most likely cause of failure is specifying an array_ptr
that points to a full (nonsparse) mxArray
.
Use mxGetJc
to obtain the starting address of the jc
array. The jc
array is an integer array having n+1
elements where n
is the number of columns in the sparse mxArray
. The values in the jc
array indirectly indicate columns containing nonzero elements. For a detailed explanation of the jc
array, see mxSetJc
.
Consider a MEX-file named SecndCol
that displays the number of nonzero elements in the second column of an input mxArray
:
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[]) { int *jc; int starting_row_index, stopping_row_index; int elements_in_second_col; /* Get the starting positions of the data in the sparse array. */ jc = mxGetJc(prhs[0]); /* How many elements are in the second column of the sparse array. */ starting_row_index = *(jc + 1); stopping_row_index = *(jc + 2); elements_in_second_col = stopping_row_index - starting_row_index; mexPrintf("There are %d elements in the second column.\n", elements_in_second_col); }In MATLAB, create a sparse
mxArray
and put four nontrivial elements in the second column:
>> sp = sparse(eye(100)); >> sp(23,2)=1; >> sp(57,2)=1; >> sp(84,2)=1;Now call
SecndCol
, passing the sparse mxArray
as an input argument:
>> SecndCol(sp); There are 4 elements in the second column.For an additional example, see
mxgetjc.c
in the mx
subdirectory of the examples
directory.
mxGetIr
, mxSetIr
, mxSetJc