Running out of memory when loading mat-file

5 views (last 30 days)
Tim
Tim on 12 Feb 2013
Hi,
When I run my model, I save all the contents in a .mat file, which becomes approximately 700mb. Subsequently, when I load it my computer becomes really slow and uses 1.200mb of memory. What can I do? I have R2011a, so I cannot use matfile yet. Furthermore, I've got a 32-bit 2GHz dual core with 2gb RAM. Is there a way to solve this?
Thanks in forward,
Tim
Below is the script that I use to save the .mat file:
clear all
use multidimensional_LV (3).ini;
rand('state', sum(100*clock));
simtime 0 5000 5000;
H=[ 1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 1 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1];
lenZ=[1:6]';
lenA=[1:10]';
muZ=(lenZ-1)*9/5+1';
H=normpdf(repmat(lenA,1,6),repmat(muZ',10,1),ones(10,6)*1);
ncnt=20;
runs = 100;
mainloop=5;
tmpl='NESTNORMPDF_%2.2d';
for newtry=1:mainloop
Hs=zeros(ncnt,10,6);
as=zeros(ncnt,10,10);
As=zeros(ncnt,runs,10);
Zs=zeros(ncnt,runs,6);
stuff=zeros(ncnt,2);
results=cell(ncnt,runs);
cnt=1;
use multidimensional_LV (3).ini;
simtime 0 5000 5000;
H=[ 1 1 1 1 1 1
0 1 1 1 1 1
0 0 1 1 1 1
0 0 0 1 1 1
0 0 0 0 1 1
0 0 0 0 1 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1
0 0 0 0 0 1];
lenZ=[1:6]'; %
lenA=[1:10]';
muZ=(lenZ-1)*9/5+1';
H=normpdf(repmat(lenA,1,6),repmat(muZ',10,1),ones(10,6)*1);
while cnt<=ncnt
Hs(cnt,:,:)=H;
as(cnt,:,:)=a;
savepar(sprintf('ini/run%s-%d',datestr(now(),'yyyymmdd'),cnt))
newnest=nestedloop2(H);
[n_group phyto zoo Q]=modularity_bipartite(H);
stuff(cnt,:)=[newnest;Q];
tic
for i=1:runs;
randinit 5;
As(cnt,i,:)=A;
Zs(cnt,i,:)=Z;
stabil 20000;
n=nmaxima;
results{cnt,i}=n;
progression=[newtry cnt i]
end;
toc
ouweH=H;
found=false;
while ~found
H=ouweH;
vindpos=find(H>0.001);
vindzeros=find(H<0.001);
vindpos=vindpos(randperm(size(vindpos,1)));
vindzeros=vindzeros(randperm(size(vindzeros,1)));
twopos=vindpos(1:2);
twozeros=vindzeros(1:2);
helpH=H(twozeros);
H(twozeros)=H(twopos);
H(twopos)=helpH
found=all(sum(H)>0) && all(sum(H,2)>0);
end
cnt=cnt+1;
fnam=sprintf(tmpl,newtry);
save(fnam,'results','As','Zs','Hs','stuff', 'as');
end
end

Answers (1)

Jan
Jan on 12 Feb 2013
When the MAT file has 700MB and it is written in a compressed format (-v7.3), loading it will need as much RAM as it needs. Please check "whos" after loading the file to see how much memory the data need.
There is no magic trick to get more memory, but only the trivial suggestions:
  • Install more RAM
  • Use a 64-bit OS and Matlab

Categories

Find more on Programming in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!