| External Interfaces/API Reference | ![]() |
Set the jc array of a sparse mxArray
C Syntax
Arguments
array_ptr
Pointer to a sparse mxArray.
Description
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. The values in the jc array have the meanings:
jc[j] is the index in ir, pr (and pi if it exists) of the first nonzero entry in the jth column.
jc[j+1]-1 is the index of the last nonzero entry in the jth column.
jc[number of columns + 1] is equal to nnz, which is the number of nonzero entries in the entire spare mxArray.
The number of nonzero elements in any column (denoted as column C) is
For example, consider a 7-by-3 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 contents of the ir, jc, and pr arrays are:
| Subscript |
ir |
pr |
jc |
Comment |
(2,1) |
1 |
|
|
|
(5,1) |
4 |
|
|
|
(3,2) |
2 |
|
|
|
(2,3) |
1 |
|
|
|
(5,3) |
4 |
|
|
|
(6,3) |
5 |
|
|
|
As an example of a much sparser mxArray, consider an 8,000 element sparse mxArray named Spacious containing only three nonzero elements. The ir, pr, and jc arrays contain:
| Subscript |
ir |
pr |
jc |
Comment |
(73,2) |
72 |
|
|
|
(50,3) |
49 |
|
|
|
(64,5) |
63 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|||
|
3 |
|||
|
3 |
Examples
See mxsetdimensions.c in the mx subdirectory of the examples directory. For an additional example, see explore.c in the mex subdirectory of the examples directory.
See Also
| mxSetIr | mxSetLogical (Obsolete) | ![]() |