same code but with different behavior each time

조회 수: 2 (최근 30일)
huda nawaf
huda nawaf 2011년 12월 3일
I have file with large length (2444546), so I segmented it into 2 parts,each part with length(1222273).With total length i got out of memory and run this code:
fid = fopen('d:\matlab\r2011a\bin\flixsterdata\finalflix0.txt','r');
c = textscan(fid,'(%d,%d)\t%d')
c1=c{1};c2=c{2};c3=c{3};
LL=length(c1)
L=round(LL/2)
w=double(c1(1:L)); w1=double(c2(1:L)); w2=double(c3(1:L));
flix0=accumarray([w,w1],w2);
[m,n]=size(flix00);
f=fopen('flix00.txt','w');
for i=1:m
for j=1:n
fprintf(f,'%d',flix00(i,j));
end
end
fclose all
I ran this code for the first part, and no problem
But when I ran the same code for the second part , where start from 1222274(code below), I got this error:
??? Error using ==> accumarray
Out of memory. Type HELP MEMORY for your
options.
Error in ==> g at 8 flix0=accumarray([w,w1],w2);
the same code and for the same size of file , but it's behavior is different
fid = fopen('d:\matlab\r2011a\bin\flixsterdata\finalflix0.txt','r');
c = textscan(fid,'(%d,%d)\t%d','headerLines', 1222274); c1=c{1};
c2=c{2};c3=c{3}; LL=length(c1) L=round(LL/2) w=double(c1(1:L));
w1=double(c2(1:L)); w2=double(c3(1:L));
flix0=accumarray([w,w1],w2);
  댓글 수: 1
Jan
Jan 2011년 12월 3일
Please, huda, format your code properly to make the reading easier.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2011년 12월 3일
Like I told you before, use %f format in doing your reads, and skip the double() step. You should be avoiding making copies of your input.

카테고리

Help CenterFile Exchange에서 Whos에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by