Path: news.mathworks.com!newsfeed-00.mathworks.com!nntp.TheWorld.com!support1.mathforum.org!not-for-mail
From: juckou <ja79@hw.ac.uk>
Newsgroups: comp.soft-sys.matlab
Subject: Memory problems
Date: Fri, 07 Nov 2008 14:49:14 EST
Organization: The Math Forum
Lines: 88
Message-ID: <12408444.1226087385326.JavaMail.jakarta@nitrogen.mathforum.org>
NNTP-Posting-Host: nitrogen.mathforum.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Trace: support1.mathforum.org 1226087385 15302 144.118.30.135 (7 Nov 2008 19:49:45 GMT)
X-Complaints-To: news@news.mathforum.org
NNTP-Posting-Date: Fri, 7 Nov 2008 19:49:45 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:499581


Dear all,

I've the following code running for about 500 images (satellite composites of sea surface temperature):

for i=1:length(imageslist)
disp(num2str(i));
temp = imread(imageslist{i});
temp2=double(temp);
temp2(find(temp2==max(temp2(:))))=0;
temp2(find(temp2==0))=NaN;

mymatrix(:,:,i) = temp2;

It doesn't finish running the code with all the images and stops saying "out of memory". Then I've used:

mymatrix=zeros(365,525,506);%506 images of 365 rows and 525 columns each 

to force matlab to use just the right amount of memory. Then the code runs fine but when I try to write mymatrix into a file it shows again the "out of memory" error. I'm using the following gwrite function to write mymatrix into a file:

function flag = gwrite(name,tab)

[imax,jmax,kmax] = size(tab);
valex = 9999;
nbmots = imax*jmax*kmax;

c4 = reshape(tab,imax*jmax*kmax,1);
c4(find(isnan(c4))) = valex;
[flag]=uwrite(name,c4,imax,jmax,kmax,valex,nbmots);

function [flag]=uwrite(file,c4,imax,jmax,kmax,valex,nbmots)
flag=0;
file;
dummy=0;
dummyf=0.;
dummy24=24;
iprec=4;
fid=fopen(file,'w','ieee-be');
if fid~=-1
ind=find(isnan(c4));
c4(ind)=valex;
if nbmots==-1
 nbmots=imax*jmax*kmax
end
for i=1:10
 fwrite(fid,dummy,'int32');
 fwrite(fid,dummy,'int32');
end
nl=fix((imax*jmax*kmax)/nbmots);
ir=imax*jmax*kmax-nbmots*nl;
dummyval2=4*nbmots;
fwrite(fid,dummy24,'int32');
fwrite(fid,imax,'int32');
fwrite(fid,jmax,'int32');
fwrite(fid,kmax,'int32');
fwrite(fid,iprec,'int32');
fwrite(fid,nbmots,'int32');
fwrite(fid,valex,'single');
fwrite(fid,dummy24,'int32');

if imax<0 | jmax<0 | kmax<0
 nl=0;
 ir=4;
 disp('Degenerated matrix');
end

ide=1;

for kl=1:nl
 fwrite(fid,4*nbmots,'int32');
 fwrite(fid,c4(ide:ide+nbmots-1),'single');
 fwrite(fid,4*nbmots,'int32');
 ide=ide+nbmots;
end

fwrite(fid,4*ir,'int32');
fwrite(fid,c4(ide:ide+ir-1),'single');
fwrite(fid,4*ir,'int32');

flag=1;
fclose(fid);
end

I don't think the variable is that big to run out with all the memory. Do you know what could be done to deal with those memory problems and allow writting the matrix into a file using gwrite?

Thank you very much for any help

regards
juckou