Replace elements of sparse matrix from a full matrix.

4 vues (au cours des 30 derniers jours)
KSSV
KSSV le 4 Mar 2016
Dear Experts
I have a huge matrix, M with zeros. I am converting M into sparse using sparse(M). After, I want to replace few positions (idx) of M from other matrix, N. I am using the following: M(idx) = N(idx). But, this is very very slow. Also MATLAB warns: This sparse indexing expression is slow. How I can do the above task?
Thanks in advance.
  2 commentaires
Stephen23
Stephen23 le 4 Mar 2016
What size is M?
KSSV
KSSV le 4 Mar 2016
[19647672 60] is the size at present am dealing with. It may be more in future.

Connectez-vous pour commenter.

Réponses (1)

Jos (10584)
Jos (10584) le 4 Mar 2016
What don't you replace the elements before converting it?
  8 commentaires
KSSV
KSSV le 5 Mar 2016
Actually my original matrix has zeros and I want to fill these zeros with numbers later...
Walter Roberson
Walter Roberson le 5 Mar 2016
Then spalloc() would be appropriate. If you create a matrix without using it or equivalent then you end up doing a lot of sparse reallocations as you add in new values.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Sparse 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!

Translated by