Converting nested for loops to vectors
2 ビュー (過去 30 日間)
古いコメントを表示
All,
I'm trying to convert the following code from nested for loops in order to improve efficiency.
c = 1;
output = zeros(n*m*z,1)
for i =1:n
for j = 1:m
for k = 1:z
output(c,:) = function(i, j, k);
c = c + 1;
end
end
end
is this something that can be vectorized or do I have to try to use the parallel computing toolbox and make use of the parfor looping?
thanks,
dan
2 件のコメント
Stephen23
2016 年 1 月 19 日
編集済み: Stephen23
2016 年 1 月 19 日
Vectorization does not mean replacing my slow loops with some other code, it means writing functions that operate on entire arrays at once.
This means it is the function that is important, not the loops. However you do not tell us anything about the function, yet it is the only important thing to consider. If you give us details about the function then we can give advice about vectorization.
In general vectorization is more efficient than jumping into using parallel computing.
回答 (0 件)
参考
カテゴリ
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!