【发布时间】:2017-08-12 18:52:18
【问题描述】:
我正在处理一个相当大的稀疏矩阵,它的大小约为 150,000*150,000。我需要访问它的行,提取非零元素并按照以下规则替换这些值:
tic
H = [];
for i = 1: size(A,2)
[a,b,c] = find(A(i,:)); % extract the rows
add = diff([0 c(2:end) 0]); % the replacing rule
aa = i*ones(1,size(a,2)); % return back the old position of rows
G0 = [aa' b' add']; % put it back the old position with replaced values
H = [H; G0];
end
H1 = H(:,1);
H2 = H(:,2);
H3 = H(:,3);
ADD = sparse(H1,H2,H3,nm,nm,nzmax);
toc
我发现find 函数在这段代码中非常耗时(0.1 秒/行),并且在我的稀疏矩阵的当前大小下,这项工作最多需要 33 个小时。我确实相信有一些出路,但我是个新手,编码和处理稀疏矩阵真的很可怕。
你能给我一些想法吗?
【问题讨论】:
标签: matlab matrix replace sparse-matrix