Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
一个简单的问题,我有一个稀疏矩阵 A 和一个索引列表b = [2, 3, 4 ...],我想设置 A(2, 2), A(3, 3), A(4, 4)... = 0. 我试过A(b, b) = 0,结果是A(2, 3), A(2, 4), A(3, 2), A(3, 4), A(4, 2), A(4, 3)这个矩阵的一些非对角元素也被置为零,怎么处理呢?
b = [2, 3, 4 ...]
A(2, 2), A(3, 3), A(4, 4)... = 0
A(2, 3), A(2, 4), A(3, 2), A(3, 4), A(4, 2), A(4, 3)
使用线性索引:
A(sub2ind(size(A),b,b)) = 0;
这适用于完整或稀疏矩阵。