请问MATLAB中的sparse函数怎样使用?

来源:百度知道 编辑:UC知道 时间:2024/05/11 21:30:47
下面是 help sparse 的帮助文件, 谁要是用的比较熟悉,给介绍一下吧.

SPARSE Create sparse matrix.

S = SPARSE(X) converts a sparse or full matrix to sparse form by squeezing out any zero elements.

S = SPARSE(i,j,s,m,n,nzmax) uses the rows of [i,j,s] to generate an m-by-n sparse matrix with space allocated for nzmax nonzeros.

The two integer index vectors, i and j, and the real or complex entries vector, s, all have the same length, nnz, which is the number of nonzeros in the resulting sparse matrix S .

Any elements of s which have duplicate values of i and j are added together.

There are several simplifications of this six argument call.

S = SPARSE(i,j,s,m,n) uses nzmax = length(s).

S = SPARSE(i,j,s) uses m = max(i) and n = max(j).

S = SPARSE(m,n) abbreviates SPARSE([],[],[],m,n,0). This
generates the ultimate sparse matrix, an m-by-n all zero matrix.

sparse是生成一个稀释矩阵,S=sparse(i,j,s,m,n)是用向量i,j和s生成一个m×n的稀释矩阵,i和j是行下标和列下标
spdiags功能:返回带状稀疏矩阵Aspdiags的格式为:
A=spdiags(B,d,m,n)参数m,n为原带状矩阵的行数与列数。B为r×p阶矩阵,这里r=min(m,n),p为原带状矩阵所有非零对角线的条数,矩阵B的第i列即为原带状矩阵的第i条非零对角线, d为长度为p的向量。

y=sparse(x) %将一个矩阵转为sparse矩阵存储。
[i,j,z]=find(x) %对一个sparse矩阵x,查找其中非零元素得位置(行标和列标)和值。
x = sparse(i,j,x);指定非零元素得行标,列标和值,创建sparse矩阵。