sparse的使用方法,每次使用都忘记,这几转载过来

MATLAB provides a sparse function of the form

matrix = sparse ( i, j, s, m, n, nz_max )
This function can be used to create a sparse matrix. The input arguments have the following meaning:

i:the row indices of the nonzero elements;

j:the column indices of the nonzero elements;

s:the values of the nonzero elements;

m: the number of rows in the matrix;%所要创建的稀疏矩阵的行数

n:the number of columns in the matrix; %所要创建的稀疏矩阵的列数

nz_max:the maximum number of nonzero elements in the matrix;  nz_max is commonly omitted, in which case its value is taken from the length of  s.

Note that nz_max is commonly omitted, in which case its value is taken from the length of s. Moreover, if you specify nz_max explicitly, or implicitly through the size of s, MATLAB will allow you to increase the number of nonzero elements at any time. Specifying nz_max correctly, then, is simply a matter of efficiency.

使用例子:稀疏矩阵如下

 	11  12   0   0  15
         0  22  23   0   0
        31   0  33  34  35
在matlab中输入如下参数:
  	i = [  1,  1,  1,  2,  2,  3,  3,  3,  3 ];%注意当i和j有重复的下表时候,稀疏矩阵会相加s中的值
        j = [  1,  2,  5,  2,  3,  1,  3,  4,  5 ];
        s = [ 11, 12, 15, 22, 23, 31, 33, 34, 35 ];
        m = 3;
        n = 5;
        nz_max = 9;

        a = sparse ( i, j, s, m, n, nz_max );

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值