How to quickly accumulate values into sparse matrix from very large row,col and value arrays containing duplicates indices?
5 views (last 30 days)
Show older comments
Hi,
I'd like to fill a large (sparse) matrix. I have three very long arrays of rowidx, colidx and values. row col combination can appear several times in those arrays and I'd like to add the corresponding values into the matrix at that location
% alloc sparse zero matrix
A = spalloc(vnum,vnum,vnum*maxdeg);
% I and J are row and col idxs
% val is the vector of values (all same length)
for i = 1:length(I)
A(I(i),J(i)) = A(I(i),J(i)) + val(i);
end
Takes forever. Is there a faster way? I tried also this
Idx = I+vnum*(J-1);
v = accumarray(Idx,val);
to sum up the duplicates first, but that gives me out of memory (maybe it creates a dense large matrix internally?).
Any help appreciated
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!