is there fast way for this problem
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
hi, is there a fast way to deal with this problem:
I have 17770 files, each file has structure as:
id_user(integer), rate(integer),date
each file has unique id_user but may share these id_users with other files.
what I want is: each unique id _user be row in array such as: id_user1: rate1 date1 rate3 date3......raten daten id_user2: rate3 date3..rate20 date20........... etc..
I mean rate1 for ex. is rate of user1 in file 1 and rate3 in file 3 and so on. where id_user1 for ex. be in file 1 and file 3 id_user2 be in file 3 and file 20
I wrote code , it is work correctly, but very very slow, it need three hours to creat array with just 50 id_users(read all 17770). I have 480000 id's of users,I have to look for their ratings in 17770 files. I placed my files in folder, then read it one after one. I looked for unique id of users ,then use function (find)in all 17770. Each time looked for id of 30 users as ex. n all files ,then record their ratings in array , but this process take long time, where to accumulate data for 30 users take three hours .
any suggestions, advices may help me
thanks in advance
댓글 수: 0
답변 (1개)
Robert Cumming
2012년 1월 9일
are you preallocating? use the profiler to help locate the time where the code takes longest
profile on
% run your code
profile viewer
Run on a subset of your files for testing - then expand to include more files.
댓글 수: 9
huda nawaf
2012년 1월 9일
per isakson
2012년 1월 9일
see: http://undocumentedmatlab.com/blog/datenum-performance/
huda nawaf
2012년 1월 9일
huda nawaf
2012년 1월 9일
Robert Cumming
2012년 1월 10일
The other functions will be called by functions you wrote. As well as the total time - look at the functions that called the most - any small saving in that will have a much larger effect.
Is your table above saying that you have 1507 calls to datenum - and that takes 1178 seconds!? That doesn't look right to me.... Or am I misinterpreting the table.
Also check you are pre-allocating any arrays.
huda nawaf
2012년 1월 10일
Robert Cumming
2012년 1월 10일
Pre-allocating the rows only is not good enough - you have to preallocate the full matrix - why cant you pre-allocate the columns?
On the error the function is not found by matlab - can you find it manually?
huda nawaf
2012년 1월 11일
Robert Cumming
2012년 1월 11일
either preallocate tobigger than you need and check that it does not grow - or do a preloop to determine size. it will speed things up.
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!