Main Content

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 sparsemxArray

jc

Pointer to thejcarray

Description

UsemxSetJcto specify a newjcarray for a sparsemxArray. Thejcarray is an integer array havingn+1elements, wherenis the number of columns in the sparsemxArray.

If thejth column of the sparsemxArrayhas any nonzero elements, then:

  • jc[j]is the index inir,公关, andpi(if it exists) of the first nonzero element in thejth column.

  • jc[j+1]-1is the index of the last nonzero element in thejth column.

  • For thejth column of the sparse matrix,jc[j]is the total number of nonzero elements in all preceding columns.

The number of nonzero elements in thejth column of the sparsemxArrayis:

jc[j+1] - jc[j];

For thejth column of the sparsemxArray,jc[j]is the total number of nonzero elements in all preceding columns. The last element of thejcarray,jc[number of columns], is equal tonnz, which is the number of nonzero elements in the entire sparsemxArray.

For example, consider a7-by-3sparsemxArraynamedSparrowcontaining 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

(2,1)

1

1

0

Column 1 contains two nonzero elements, with rows designated by红外[0]andir[1]

(5,1)

4

1

2

Column 2 contains one nonzero element, with row designated byir[2]

(3,2)

2

1

3

Column 3 contains three nonzero elements, with rows designated byir[3],ir[4], andir[5]

(2,3)

1

2

6

There are six nonzero elements in all.

(5,3)

4

1

(6,3)

5

1

As an example of a much sparsermxArray, consider a1000-by-8sparsemxArraynamedSpaciouscontaining only three nonzero elements. Their,公关, andjcarrays contain the values listed in this table.

Subscript

ir

公关

jc

Comment

(73,2)

72

1

0

Column 1 contains no nonzero elements.

(50,3)

49

1

0

Column 2 contains one nonzero element, with row designated by红外[0].

(64,5)

63

1

1

Column 3 contains one nonzero element, with row designated byir[1].

2

Column 4 contains no nonzero elements.

2

Column 5 contains one nonzero element, with row designated byir[2].

3

Column 6 contains no nonzero elements.

3

Column 7 contains no nonzero elements.

3

Column 8 contains no nonzero elements.

3

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, callmxFreeon the pointer returned bymxGetJcbefore you callmxSetJc.

Examples

See these examples inmatlabroot/extern/examples/mx:

See these examples inmatlabroot/extern/examples/mex:

版本历史

Introduced before R2006a