How can I speed up assignments to sparse matrices in MATLAB?
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
How can I speed up assignments to sparse matrices in MATLAB?
I am assigning values to a sparse matrix which I have already created. However, this seems to be very slow. Is there a way to make this process faster?
Risposta accettata
MathWorks Support Team
il 27 Giu 2009
Here are two suggestions for speeding up the assignment of values to sparse matrices:
1) Using SPALLOC, specify the number of nonzero elements that the sparse matrix will have. This will allow you to specify how much space should be allocated. If you know that you will be assigning new values, you can specify more space than you initially use. This way, MATLAB will not need to reallocate extra memory later.
2) If you are creating a sparse vector, use a column vector instead of a row vector. MATLAB needs to keep track of every column of the sparse matrix, so if you use a column vector instead of a row vector, then it will only need to keep track of a single column, which will save memory and processing time.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Sparse Matrices in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!