Which is faster, the sparse or spdiag function?

In each iteration of a for loop I'm creating a big (approximatlly 10k*10k) five diagonal sparse matrix. Does anybody knows which function work faster? The sparse or spdiags. Is there a faster way to it if I only update the values of an existing sparse matrix in each iteration?

2 comentarios

Walter Roberson
Walter Roberson el 10 de Abr. de 2018
Be careful, updating an existing sparse matrix is slow if you are adding non-zero elements beyond what was allocated for the matrix with spalloc()
James Tursa
James Tursa el 10 de Abr. de 2018
Even if you are not exceeding the currently allocated memory for the matrix, it can be slow if the operation causes a large number of existing elements to be moved around in this memory.

Iniciar sesión para comentar.

Respuestas (1)

Walter Roberson
Walter Roberson el 10 de Abr. de 2018

0 votos

spdiags() invokes sparse() after packaging together the appropriate content and indices.

1 comentario

d
d el 11 de Abr. de 2018
So, it means that sparse() is better in terms of time consuming. Thanks.

Iniciar sesión para comentar.

Categorías

Más información sobre Sparse Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

d
d
el 10 de Abr. de 2018

Comentada:

d
d
el 11 de Abr. de 2018

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by