How to fastly construct a sparse matrix with each column equal to some sparse vector
Show older comments
Dear community,
I have 2000 sparse arrays H(i), i=1,...2000, with each of size 100000*5, now I'd like to construct a new sparse matrix X of size 100000*2000 with its i-th column equal to the first column of H(i). The simple way is just a loop:
X = sparse(100000,2000);
for i=1:2000
X(:,i) = H(:,1);
end
However, Such an assignment is slow. Is there any better way? Thanks !
Bo
2 Comments
Fabio Freschi
on 26 Sep 2019
Edited: Fabio Freschi
on 26 Sep 2019
Not clear: is H an array (you use H(i)) or a matrix (in the loop: H(:,1)). or maybe a cell array where each H{i} is a 100000*5 matrix?
Can you share the data to play with?
yu wen
on 26 Sep 2019
Answers (0)
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!