mxSetJc (C and Fortran)
JC array of sparse array
C Syntax
#include "matrix.h" void mxSetJc(mxArray *pm, mwIndex *jc);
Fortran Syntax
#include "fintrf.h" subroutine mxSetJc(pm, jc) mwPointer pm, jc
Arguments
-
pm
-
Pointer to a sparse
mxArray
-
jc
-
Pointer to the
jc
array
Description
UsemxSetJc
to specify a newjc
array for a sparsemxArray
. Thejc
array is an integer array havingn+1
elements, wheren
is the number of columns in the sparsemxArray
.
If thej
th column of the sparsemxArray
has any nonzero elements, then:
jc[j]
is the index inir
,公关
, andpi
(if it exists) of the first nonzero element in thej
th column.jc[j+1]-1
is the index of the last nonzero element in thej
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 thej
th column of the sparsemxArray
is:
jc[j+1] - jc[j];
For thej
th column of the sparsemxArray
,jc[j]
is the total number of nonzero elements in all preceding columns. The last element of thejc
array,jc[
number of columns]
, is equal tonnz
, which is the number of nonzero elements in the entire sparsemxArray
.
For example, consider a7
-by-3
sparsemxArray
namedSparrow
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 their
,jc
, and公关
arrays.
Subscript |
ir |
公关 |
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 sparsermxArray
, consider a1000
-by-8
sparsemxArray
namedSpacious
containing only three nonzero elements. Their
,公关
, andjc
arrays contain the values listed in this table.
Subscript |
ir |
公关 |
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, callmxFree
on the pointer returned bymxGetJc
before you callmxSetJc
.
Examples
See these examples in
:matlabroot
/extern/examples/mx
See these examples in
:matlabroot
/extern/examples/mex