Vectorized operation of sparse matrix
Ältere Kommentare anzeigen
I have the following code
a = randi(903,10293,1800);
c = cell(1,10293);
for n = 1:10293
b = a(n,:);
i = b(1:length(b)-1);
j = b(2:length(b));
k = ones(1,length(b)-1);
s = sparse(i,j,k,903,903);
total = nansum(s,2);
p = s./total;
c{n} = p;
end
After it runs for sometime, matlab runs out of memory. Without the """ total = nansum(s,2); p = s./total; """ part, and setting c{n} =s, it runs fine. Can anyone tell me how to fix this and make the code run efficiently?
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Sparse Matrices finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!