Vectorize the code of a summation written with nested for loops
古いコメントを表示
Hi everyone,
I want to implement the following inequality in an efficient form (it's part of an optimization problem I'm solving with the genetic algorithm from the Global Optimization Toolbox):

I still realised it straight with some for loops, like you can see in the code:
for k = 1:K
summation = 0;
for w = 1:W
for m = 1:M
summation = summation + a(m) * y(m,k,w);
end
end
ineq(k) = summation - c(k);
end
And because Matlab is slow with loops, I want to vectorize my code. This is how far i got:
for w = 1:W
summation(w,k) = a(m) * y(m,k,w);
end
summation = sum(summation);
ineq = summation - c;
Finally I really don't how to replace the last for loop. It would be great if someone has a solution for it or another idea how to implement the inequality in vectorized form.
1 件のコメント
Jonas Kreich
2016 年 11 月 14 日
採用された回答
その他の回答 (1 件)
Jonas Kreich
2016 年 11 月 14 日
カテゴリ
ヘルプ センター および File Exchange で Vector Volume Data についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
