Reshaping is causing memory problem
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Saddam N Y
am 5 Feb. 2024
Kommentiert: Saddam N Y
am 6 Feb. 2024
Hello everyone,
I have 500 matrices of huge size of 40834 x 40834 and I would like to load them from mat files and then flatten them using the reshape function and later do some other things. However in the first flatteing operation I am getting a memory issue and Matlab aborts. How one could solve such a problem ? The code is below, here all Ki.mat are sparse matrices. Thank you.
i=1;
K_matrix_file = strcat('Matrices/K',num2str(i),'.mat');
load(K_matrix_file);
K_flatten = reshape(K_i,1,[]);
Saddam
3 Kommentare
Akzeptierte Antwort
Matt J
am 5 Feb. 2024
Bearbeitet: Matt J
am 5 Feb. 2024
Don't make long sparse row vectors, as these do consume lots of memory. Work with column vectors instead:
K_flatten = K_i(:);
2 Kommentare
Walter Roberson
am 5 Feb. 2024
t0 = spalloc(1,0,2);
t1 = spalloc(1,100,2);
t2 = spalloc(1,101,2);
whos t0 t1 t2
t1(1,100) = 1;
t2(1,100) = 1;
whos t1 t2
t1(1,50) = 2;
t2(1,50) = 2;
whos t1 t2
In short, a sparse row vector takes 8 bytes plus 8 bytes per column plus 16 bytes per non-zero.
This is a more than the equivalent non-sparse row vector, which would take 8 bytes per column.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!