Simple Question about Optimization of Nested IF-FOR loops
    9 ビュー (過去 30 日間)
  
       古いコメントを表示
    
Does any one know how to optimize this code so that it runs faster:
 for i=1:iNZ;
        if iPointsinSlice>0;
            for m=1:iNX;
                for l=1:iNY;
                    if SliceMaskUr(m,l)==1;
                        DoseCubeU(m,l,i)=100*SumDose(m,l,i)/RX_Dose;
                    end
                end
            end
        end
    end
Thanks a lot!
0 件のコメント
回答 (1 件)
  Kye Taylor
      
 2013 年 6 月 18 日
        First of all, it appears that each time through the outer-most loop (the first one), the variable iPointsinSlice does not change. Therefore, you can simplify to
for i=1:iNZ;
  for m=1:iNX;
    for l=1:iNY;
      if SliceMaskUr(m,l)==1;
        DoseCubeU(m,l,i)=100*SumDose(m,l,i)/RX_Dose;
      end
    end
  end
end
but i bet you actually mean to have some expression that depends on i execute before the loop that iterates over m.
参考
カテゴリ
				Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
			
	製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

