Matlab out of memory when use index to access an element of an array
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Here is my code:
rows = zeros(round(a large number),1);
cols = rows;
vals = rows;
.....(calculation)
rows(idx) = (i-1)*p + j;
cols(idx) = col;
vals(idx) = d;
Here, idx, pj, col, d are four arrays of the same size. The first indexing line (rows(idx) = (i-1)*p + j;) gets no problem. But when excuting the next line, it comes the problem "out of memory".
I set a breakpoint and debug here. After excuting "rows(idx) = (i-1)*p + j;", i tried "cols(1)=1", it also got the out of memory problem. Could someone pleas explain this problem to me? Thanks a lot!
0 Commenti
Risposta accettata
Matt Fig
il 6 Dic 2012
Modificato: Matt Fig
il 6 Dic 2012
You are probably seeing copy-on-write behavior. When you first assign the value of rows to cols, MATLAB doesn't actually create cols, but rather a pointer to rows. It is only when you change a value in cols that MATLAB (tries to) create cols. This is when you run out of memory.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Performance and Memory in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!