Speeding up nested for-loop

1 回表示 (過去 30 日間)
Niles Martinsen
Niles Martinsen 2015 年 8 月 24 日
コメント済み: Star Strider 2015 年 8 月 24 日
Hi
I have the following nested for-loop, containing some if-statements. It is running horribly slow, so I would be very happy to get some hints and tricks to speed it up. Can I vectorize it somehow? Or use parallel computing?
for xi= 1:N
for yi= 1:N
a = A(:,xi,yi); %a is a vector
b = B(:,xi,yi); %b is a vector
D = a-b;
if( max(D./a)<1e-3 )
test_var=2.0;
else
F_min = F(a, b, 0); %F is a script I wrote
F_max = F(a, b, 1); %F is a script I wrote
if( F_min*F_max>0.0 )
test_var=2.0;
else
test_var = F(a, b, 2);
end
end
var(1, xi,yi) = test_var;
end
end
  1 件のコメント
Star Strider
Star Strider 2015 年 8 月 24 日
It might help if you describe what you want to do in your code, the sizes of ‘A’ and ‘B’ (although they are likely equal), and listed ‘F’ and describe what it does.

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by