Operations on sparse matrices return sparse matrices and operations on full matrices return full matrices. This generates the ultimate sparse matrix, an m-by- n all zero matrix.Īll of the MATLAB built-in arithmetic, logical, and indexing operations can be applied to sparse matrices, or to mixtures of sparse and full matrices. The maxima are computed before any zeros in s are removed, so one of the rows of might be. To simplify this six-argument call, you can pass scalars for the argument s and one of the arguments i or j-in which case they are expanded so that i, j, and s all have the same length. If any value in i or j is larger than the maximum integer size, 2^31-1, then the sparse matrix cannot be constructed. Any elements of s that have duplicate values of i and j are added together. Any elements of s that are zero are ignored, along with the corresponding values of i and j. Vectors i, j, and s are all the same length. Uses vectors i, j, and s to generate an m-by- n sparse matrix such that S(i(k),j(k)) = s(k), with space allocated for nzmax nonzeros.
If S is already sparse, sparse(S) returns S. The sparse function generates matrices in the MATLAB sparse storage organization.Ĭonverts a full matrix to sparse form by squeezing out any zero elements.
Sparse (MATLAB Functions) MATLAB Function Reference