JC array of sparse array
#include "matrix.h" void mxSetJc(mxArray *pm, mwIndex *jc);
subroutine mxSetJc(pm, jc) mwPointer pm, jc
pm
Pointer to a sparse mxArray
jc
Pointer to the jc
array
Use mxSetJc
to specify a new jc
array
for a sparse mxArray
. The jc
array
is an integer array having n+1
elements, where n
is
the number of columns in the sparse mxArray
.
If the j
th column of the sparse mxArray
has
any nonzero elements:
jc[j]
is the index in ir
, pr
,
and pi
(if it exists) of the first nonzero element
in the j
th column.
jc[j+1]1
is the index of the last
nonzero element in the j
th column.
For the j
th column of the sparse
matrix, jc[j]
is the total number of nonzero elements
in all preceding columns.
The number of nonzero elements in the j
th
column of the sparse mxArray
is:
jc[j+1]  jc[j];
For the j
th column of the sparse mxArray
, jc[j]
is
the total number of nonzero elements in all preceding columns. The
last element of the jc
array, jc[
number
of columns]
, is equal to nnz
,
which is the number of nonzero elements in the entire sparse mxArray
.
For example, consider a 7
by3
sparse mxArray
named Sparrow
containing
six nonzero elements, created by typing:
Sparrow = zeros(7,3); Sparrow(2,1) = 1; Sparrow(5,1) = 1; Sparrow(3,2) = 1; Sparrow(2,3) = 2; Sparrow(5,3) = 1; Sparrow(6,3) = 1; Sparrow = sparse(Sparrow);
The following table lists the contents of the ir
, jc
,
and pr
arrays.
Subscript  ir  pr  jc  Comment 




 Column 1 contains two nonzero elements, with rows designated
by 



 Column 2 contains one nonzero element, with row designated
by 



 Column 3 contains three nonzero elements, with rows designated
by 



 There are six nonzero elements in all. 


 



As an example of a much sparser mxArray
,
consider a 1000
by8
sparse mxArray
named Spacious
containing
only three nonzero elements. The ir
, pr
,
and jc
arrays contain the values listed in this
table.
Subscript  ir  pr  jc  Comment 




 Column 1 contains no nonzero elements. 



 Column 2 contains one nonzero element, with row designated
by 



 Column 3 contains one nonzero element, with row designated
by 
 Column 4 contains no nonzero elements.  
 Column 5 contains one nonzero element, with row designated
by  
 Column 6 contains no nonzero elements.  
 Column 7 contains no nonzero elements.  
 Column 8 contains no nonzero elements.  
 There are three nonzero elements in all. 
This function does not free any memory allocated for existing
data that it displaces. To free existing memory, call mxFree
on
the pointer returned by mxGetJc
before you call mxSetJc
.
See the
following examples in matlabroot
/extern/examples/mx
.
See the
following examples in matlabroot
/extern/examples/mex
.