calculation of a sparse matrix
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
the cyclist
le 5 Avr 2011
Can you give a hint at the code your wrote?
Do you know roughly now many non-zero element in the array?
Réponse acceptée
the cyclist
le 5 Avr 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 commentaires
the cyclist
le 5 Avr 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.]
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Resizing and Reshaping Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!