problem in this code
Mostra commenti meno recenti
hi,
I have ran this code since more than 4 hours ,and did not complete yet. where is the problem ?
I read 1000 files, but the running time in unreasonable:
%%%%%%%%%%%%%%%%%%5
arr1=sparse(1000,232944);
targetdir = 'd:\social net\dataset\netflix\netflix_2\training_set';
%%nofusers=480189
targetfiles = '*.txt';
fileinfo = dir(fullfile(targetdir, targetfiles));
for i = 1:1000
thisfilename = fullfile(targetdir, fileinfo(i).name);
f = fopen(thisfilename,'r');
c = textscan(f, '%f %f %s', 'Delimiter', ',', 'headerLines', 1);
fclose(f);
c1=sparse(length(c));c2=sparse(length(c1));c3=sparse(length(c));
c1 = c{1};
c3=c{3};
L(i)=length(c1);
format long
dat=round(datenum(c3,'yyyy-mm-dd'));
arr=[c1 dat];
arr1(i,1:L(i)*2)=reshape(arr.',1,[]);
end
10 Commenti
Fangjun Jiang
il 22 Nov 2011
Please format your code.
Image Analyst
il 22 Nov 2011
Put disp(i) in the loop and see how many i's it prints out to the command line. You might also see if the printouts start to slow down as the count gets higher.
huda nawaf
il 23 Nov 2011
huda nawaf
il 23 Nov 2011
huda nawaf
il 23 Nov 2011
Image Analyst
il 23 Nov 2011
No, "f" is the id of the file. "i" is your loop counter. So it just slows down more and more at each iteration until it finally grinds to a halt? I can't really help much since I don't have your files. How big does i get before it take more than about 5 seconds per iteration? Why do you need to reshape arr? Why can't you just construct it in the correct shape to begin with?
the cyclist
il 23 Nov 2011
I have not looked at your code in detail, but is it possible that as your code runs, you are using more and more memory? Maybe after a while, you are starting to use virtual memory, which will slow everything down dramatically. You can monitor that.
huda nawaf
il 23 Nov 2011
huda nawaf
il 23 Nov 2011
Daniel Shub
il 23 Nov 2011
Formatting doesn't work in comments (but thanks for trying).
Risposta accettata
Più risposte (1)
Daniel Shub
il 23 Nov 2011
I would try replacing
arr1=sparse(1000,232944);
with
arr1 = cell(1000, 1);
and
arr1(i,1:L(i)*2)=reshape(arr.',1,[]);
with
arr1{i} = reshape(arr.',1,[]);
Categorie
Scopri di più su Parallel Computing Fundamentals in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!