calculation of a sparse matrix
8 views (last 30 days)
Show older comments
I have a very large matrix, with 3,26,041 rows and columns. I tried doing the simple sparse function for calculating it. But it returns an output as "out of memory" . I have a 64 bit system with 4gb ram. Is there anyway that i can calculate it or do i need a better system ? Can anyone please help, I am new to matlab and hence require urgent help..
2 Comments
the cyclist
on 5 Apr 2011
Can you give a hint at the code your wrote?
Do you know roughly now many non-zero element in the array?
Accepted Answer
the cyclist
on 5 Apr 2011
Sorry if I am saying what you already know, but the way you have defined A, it is decidedly non-sparse. You should not use the pre-allocation to zeros.
You should initialize the matrix A using the "sparse" command, which will define the indexing into A, without allocating memory for the elements. Then you can fill it in with your loops. Hopefully, there are few enough non-zero elements in the matrix to fit into memory.
3 Comments
the cyclist
on 5 Apr 2011
Yes, I mean you should declare A as sparse instead of preallocating with zeros.
The matrix A = zeros(1000,1000) takes up 8,000,000 bytes. It will remain that size no matter how many non-zero elements you fill in. (The zeros and non-zeros take up the same memory.)
The matrix A = sparse(1000,1000) takes up 8,024 bytes; then it takes up more memory for each element you add to it. If final matrix is truly sparse (i.e. very few non-zeros), then it uses far less memory when you fill it.
The essence is that if you define it as sparse, then MATLAB doesn't waste memory storing all those zeros, which it ordinarily would if it was a (default) double-precision array.
[As a side comment, it would be good if you accept this answer, if you feel it helped, so that future questioners might find it more easily.]
More Answers (0)
See Also
Categories
Find more on Resizing and Reshaping 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!