>> A = [0 1 0; 2 0 0; 1 0 1]
A =
0 1 0
2 0 0
1 0 1
>> B = sparse(A)
B =
(2,1) 2
(3,1) 1
(1,2) 1
(3,3) 1
>> C = find(B)
C =
2
3
4
9
>>
for i = C
B(i)
end
ans =
(1,1) 2
(2,1) 1
(3,1) 1
(4,1) 1
稀疏矩阵记录就是非零的值,和它的行号,列号,然后通过链表的形式连接起来,以减少存储的空间,提高遍历的速度