# sparse

Create sparse matrix

## Description

`S = sparse(`

generates a
sparse matrix `i,j`

,`v`

)`S`

from the triplets `i`

,
`j`

, and `v`

such that
`S(i(k),j(k)) = v(k)`

. The
`max(i)`

-by-`max(j)`

output matrix has
space allotted for `length(v)`

nonzero elements.

If the inputs `i`

, `j`

, and `v`

are
vectors or matrices, they must have the same number of elements. Alternatively,
the argument `v`

and/or one of the arguments `i`

or `j`

can
be scalars.

## Examples

## Input Arguments

## Limitations

If any of the inputs

`i,j`

or`m,n`

are larger than`2^31-1`

for 32-bit platforms, or`2^48-1`

on 64-bit platforms, then the sparse matrix cannot be constructed.

## Tips

MATLAB

^{®}stores sparse matrices in compressed sparse column format. For more information, see John R. Gilbert, Cleve Moler, and Robert Schreiber's Sparse Matrices In MATLAB: Design and Implementation.The

`accumarray`

function has similar accumulation behavior to that of`sparse`

.`accumarray`

groups data into bins using*n*-dimensional subscripts, but`sparse`

groups data into bins using 2-D subscripts.`accumarray`

adds elements that have identical subscripts into the output by default, but can optionally apply any function to the bins.`sparse`

applies the`sum`

function to elements that have identical subscripts into the output (for double values) or applies the`any`

function (for logical values).

## References

[1] Gilbert, John R., Cleve Moler,
and Robert Schreiber. “Sparse Matrices in MATLAB: Design and Implementation.”
*SIAM Journal on Matrix Analysis and Applications* 13, no. 1
(January 1992): 333–356. https://doi.org/10.1137/0613024.

[2] Chen, Yanqing, Timothy A.
Davis, William W. Hager, and Sivasankaran Rajamanickam. “Algorithm 887: CHOLMOD,
Supernodal Sparse Cholesky Factorization and Update/Downdate.” *ACM
Transactions on Mathematical Software* 35, no. 3 (October 2008): 1–14.
https://doi.org/10.1145/1391989.1391995.

## Extended Capabilities

## Version History

**Introduced before R2006a**