Replace elements of sparse matrix from a full matrix.

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 Kommentare

What size is M?
KSSV
KSSV am 4 Mär. 2016
[19647672 60] is the size at present am dealing with. It may be more in future.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jos (10584)
Jos (10584) am 4 Mär. 2016

0 Stimmen

What don't you replace the elements before converting it?

8 Kommentare

KSSV
KSSV am 4 Mär. 2016
No...I want to replace in sparse matrix. Actually I am using svds for M. M is huge.
I don't get it. You do start off with a full matrix M which you convert using sparse, don't you?
KSSV
KSSV am 5 Mär. 2016
Yes..I am starting with a full matrix which has lot of zero's. Then converting it to sparse for svds. And after I have to replace certain zeros of sparse with the result obtained from svds.
If you know you are replacing zeros, then you can sparse() up the values that are going in as a second sparse matrix, and add that to the first sparse matrix.
KSSV
KSSV am 5 Mär. 2016
Hi Walter..happy to see you. Yes I tried it, but replacing the values is taking hell lot of time.
When you create your original sparse matrix, be sure to allow extra nzmax; see http://www.mathworks.com/help/matlab/ref/spalloc.html
KSSV
KSSV am 5 Mär. 2016
Actually my original matrix has zeros and I want to fill these zeros with numbers later...
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Sparse Matrices finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 4 Mär. 2016

Kommentiert:

am 5 Mär. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by