Back to Sparse Matrices
sparse
Create sparse matrix
Syntax
S = sparse(A) S = sparse(m, n) S = sparse(i, j, v) S = sparse(i, j, v, m, n)
Description
Creates a sparse matrix. With one argument, converts a dense matrix to sparse CSR format. With two arguments (m,n), creates an empty m-by-n sparse matrix. With three arguments (i,j,v), creates a sparse matrix from row indices i, column indices j, and values v. With five arguments, additionally specifies the m-by-n dimensions.
Parameters
| Name | Description |
|---|---|
| A/i | Dense matrix, or row index vector (1-based) |
| j/n(optional) | Column index vector (1-based), or number of columns |
| v(optional) | Values vector |
| m(optional) | Number of rows |
| n(optional) | Number of columns |
Returns
Sparse matrix (CSR format)