vectorization of for loop
古いコメントを表示
Hi,
I made a 2d matrix with two for loops:
for k = 1:32
for l = 1:32
P_new(l,k) = P_old(l) + (LODF(l,k) * P_old(k));
end
end
P_old is here a 32 x 1 matrix and LODF is a 32 x 32 matrix which is already computed. How can I vectorize this code to avoid the for loops? Thanks in advance.
採用された回答
その他の回答 (2 件)
Jos (10584)
2013 年 12 月 10 日
for loops are pretty fast when you use pre-allocation
P_new = zeros(32,32) ;
for k = 1:32
for l = 1:32
P_new(l,k) = P_old(l) + (LODF(l,k) * P_old(k));
end
end
カテゴリ
ヘルプ センター および 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!