same code but with different behavior each time

14 ビュー (過去 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 Center および File ExchangeWhos についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by