Function: generate a sparse matrix.
Usage:
S = sparse ()
Converts matrix A to a sparse matrix, that is, any zero element in matrix A is removed, and non-zero elements and their subscripts form the matrix S.
If a is sparse, sparse (s) returns S.
S = sparse (I, j, S, M, N, nzmax)
A m * n sparse matrix s containing nzmax non-zero elements is generated by vector I, j, S, and S (I (k), J (k )) = S (k ).
Vector I, j, and s have the same length. Corresponding to the values of vector I and j, any zero element in s will be ignored. Book.ilovematlab.cn
The duplicate values at I and j in S are superimposed.
Note: if any one of I or J is greater than the maximum Integer Range, 2 ^ 31-1, the sparse matrix cannot be created.
S = sparse (I, j, S, m, n)
Nzmax = length (s)
S = sparse (I, j, S)
Use M = max (I) and n = max (j) to calculate the maximum value before the zero element is removed in S, in [I j s], one row may be [M N 0].
S = sparse (m, n)
The abbreviation of sparse ([], [], [], M, N, 0) generates a sparse matrix where all elements of M * n are 0.
Note:
All built-in arithmetic, logical, and indexing operations in MATLAB can be applied to sparse matrices or mixed with sparse and full matrices.
The sparse matrix operation returns the sparse matrix, and the full matrix operation returns the weight matrix.
In most cases, the sparse and full matrix operations return the full matrix. The exception is that the results of the mixed operation are sparse in structure, for example,. * s is at least as sparse as matrix S.
Example:
S = sparse (1: N, 1: N, 1) generates an N * n sparse matrix, and S = sparse (eye (n, n )) the results are the same, but if most of its elements are zero, a matrix of N * n is generated temporarily. Book.ilovematlab.cn
B = sparse (10000, Pi) may not be very useful, but it can run and allow. It generates a 10000 * matrix containing only a non-zero primary color, do not use full (B) because it requires 800 mb of storage.
Analyze and reorganize a sparse matrix:
[I, j, S] = find (s );
[M, N] = size (s );
S = sparse (I, j, S, m, n );
If the last row and last column are non-zero items, the following items are available:
[I, j, S] = find (s );
S = sparse (I, j, S );