Re: [問題] 想請問如何改善運算速度已回收

看板MATLAB作者 (神無月 孝臣)時間15年前 (2009/03/24 22:43), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《lenakaho (*^^* )》之銘言: : 由於資料很大很多, : 假設要運算下面式子, : 想請問如何加快運算速度?感謝! : ===== : for i=1:16; : for j=1:16; : for wo=1:16; : U=inv([H(i,j,wo).*aa(i,j,wo) H(i,j,wo).*ab(i,j,wo);... : H(i,j,wo).*ab(i,j,wo) H(i,j,wo).bb(i,j,wo)])... : *([H(i,j,wo).*sq(i,j,wo);H(i,j,wo).*sr(i,j,wo)]); : end; : end; : end; : %H為權重 : ===== : 煩請高手指點...m(_ _)m 程式碼沒有多少 能改的可能只有從index控制下手了 像這樣可以先快一些 for i = 1 : 16 for j = 1 : 16 for wo = 1 : 16 U = inv( H(i,j,wo) .* [ aa(i,j,wo) ab(i,j,wo) ; ... ab(i,j,wo) bb(i,j,wo) ] ) ... * ( H(i,j,wo) .* [ sq(i,j,wo) ; sr(i,j,wo) ] ) ; end end end 這樣index轉換計算從原本的12次降為8次了 如果要再加快一些的話 你的那些矩陣大小我不能確定 都先當做是16x16x16好了 for i = 1 : 16 for j = 1 : 16 for wo = 1 : 16 index = sub2ind( [ 16 16 16 ] , i , j , wo ) ; U = inv( H(index) .* [ aa(index) ab(index) ; ... ab(index) bb(index) ] ) ... * ( H(index) .* [ sq(index) ; sr(index) ] ) ; end end end 這樣子的話 index轉換計算就可以從8次變為1次了 不過這些是fotran的加速寫法 matlab是不是也適用沒有試過 但記憶體儲存格式是一樣的(index索引方式也相同) 應該也可以出現同樣加速的效果 -- Deserves death! I daresay he does. Many that live deserve death. And some die that deserve life. Can you give that to them? Then be not too eager to deal out death in the name of justice, fearing for your own safty. Even the wise cannot see all ends. Gandalf to Frodo -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 220.131.229.86

03/25 12:16, , 1F
感謝^^
03/25 12:16, 1F
文章代碼(AID): #19oF6Btr (MATLAB)
文章代碼(AID): #19oF6Btr (MATLAB)