same code but with different behavior each time

2 次查看(过去 30 天)
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 个)

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