Very long execution time for loop "end" command

5 ビュー (過去 30 日間)
Ali Jamali
Ali Jamali 2015 年 3 月 12 日
コメント済み: Ali Jamali 2015 年 3 月 12 日
MATLAB profile viewer showed me that over 20% of my run-time is spend on a loop "end" command. I understand that this line is called millions of times, but there are other lines inside that loop that take less time although they actually do something! Help please.

採用された回答

Roger Stafford
Roger Stafford 2015 年 3 月 12 日
If NInj is a large number, the lines 70 and 71 are needlessly repetitive and therefore constitute a very inefficient code. If you have room for a temporary additional (NStg-1)-by-NInj matrix (D), the following code should be much faster:
D = zeros(NStg-1,NInj);
P = 2*NPrd+(j-1)*NInj;
k = (1-X)/sqrt(2);
for i = 1:NInj
t = 0;
for n = 2:NStg
t = t*X+(I(n,i)+I(n-1,i))*k;
D(n-1,i) = t;
end
end
H(P+(1:NInj),P+(1:NInj)) = D.'*D;
  3 件のコメント
per isakson
per isakson 2015 年 3 月 12 日
See transpose
Ali Jamali
Ali Jamali 2015 年 3 月 12 日
I got it. Thanks very much!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by