[問題] 關於迴圈計算速度問題已回收

看板MATLAB作者時間14年前 (2011/04/13 09:31), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
大家好,以下是我部分程式 受限於演算法的關係 我幾乎都是利用呼叫函式的方法去做 以前類似這樣的Algorithm迴圈也是跑2000次 但也大約2~3小時就完成(跑的年份還更長) 不過這次跑一次要4~5分鐘 整個跑完大約快1個禮拜 這樣速度太慢了...(年份只有3年) 是不是我都用呼叫函式去做的問題呢? 還是有其他問題? 請問有解決的方法嗎? p.s.:crosstime 函式裡面也有迴圈 謝謝大家!! ------------------------------------------------------------------------------ year_num=3; L=2000; for i=1:L for j=1:year_num-1 [temp_crosstime_delta_hat temp_EFCH_hat temp_TECH_hat temp_Malmquist_index_hat]=... crosstime(p,n,X(:,(j+1)*n-(2*n-1):(j+1)*n),Yg(:,(j+1)*n-(2*n-1):(j+1)*n),... Yb(:,(j+1)*n-(2*n-1):(j+1)*n) ,X(:,(j+1)*n-(2*n-1):(j+1)*n),... Yg(:,(j+1)*n-(2*n-1):(j+1)*n),Yb(:,(j+1)*n-(2*n-1):(j+1)*n)); Malmquist_index_hat(j*n-(n-1):j*n,1)=temp_Malmquist_index_hat; [X_star Yg_star Yb_star]=pseudosamples(p,n,temp_crosstime_delta_hat,... X(:,(j+1)*n-(2*n-1):(j+1)*n),Yg(:,(j+1)*n-(2*n-1):(j+1)*n),... Yb(:,(j+1)*n-(2*n-1):(j+1)*n)); [temp_crosstime_delta_hat_star(:,4*j-3:4*j) temp_EFCH__hat_star(:,j)... temp_TECH_hat_star(:,j) temp_Malmquist_index(:,j)]=... crosstime(p,n,X(:,(j+1)*n-(2*n-1):(j+1)*n),Yg(:,(j+1)*n-(2*n-1):(j+1)*n),... Yb(:,(j+1)*n-(2*n-1):(j+1)*n),X_star',Yg_star',Yb_star'); end trans_temp_Malmquist_index = reshape(temp_Malmquist_index,n*(year_num-1),1); Malmquist_index_hat_star(:,i)=trans_temp_Malmquist_index; disp(['L is ' num2str(i) '.']); % 秀出目前 Bootstrap 所跑完的次數 end -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.126.147.48

04/15 01:45, , 1F
去用 matlab 的 profile 分析吧
04/15 01:45, 1F

09/23 12:24, , 2F
沒附function code,請照1F的指示用profile分析吧
09/23 12:24, 2F
文章代碼(AID): #1DfFq19R (MATLAB)