Search code examples
matlabsavecell

Matlab cell saving to .mat (OUT OF MEMORY)


I have large number of data in cell (630x5). Each element in the cell contain of matrix 30xfew_thousand, and I write it to cell in a loop after computation. At the and I will save it to mat file, but while filling the cell Matlab informs that there is no more memory to use. So I decided to fill this cell row by row, clearing the others and saving new (current) row by adding it at end of mat file. Unfortunately, there is problem with saving a row of cell using save command like

save('new.mat','coefficients{i,:}','-append');% i-iteration in the loop

Only way is to save whole cell, but it is impossible in this case.

Is there a way to save a row or specific element of cell? Second argument in save command should be name of variable and there is no way to create thousands of them, it has no sense. I'd appreciate any ideas how to save large cell to mat file.


Solution

  • I would try the matfile command:

    m = matfile('new.mat','Writable',true)
    m.coefficients=cell(350,5)
    for ix=1:350
       ...
       m.coefficients{ix,:}
    end
    

    this should write to the file system on each iteration.