Sparse matrix memory problem
1 view (last 30 days)
Show older comments
I need to create really big sparse matrix, which will have very few non zero elements. I am trying to do this callling function:
A = sparse([1], [1000000000], 1);
But Matlab then allocates 7GB of memory! I think sparse matrices uses memory only for non zero elements, but it seems it allocates full matrix. Am I doing something wrong or this is Matlab bug? How can I bypass it?
0 Comments
Accepted Answer
Teja Muppirala
on 5 Apr 2012
Sparse matrices keep track of data by each column. This means that if you have a lot of columns (here you have one billion of them...), then you will need lots of memory even though it is sparse. A workaround would be to make it a single column vector with 1e9 rows instead.
A = sparse(1000000000, 1, 1);
0 Comments
More Answers (1)
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!