Converting nested for loops to vectors

2 visualizzazioni (ultimi 30 giorni)
Daniel
Daniel il 19 Gen 2016
Modificato: Stephen23 il 19 Gen 2016
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 Commenti
Stephen23
Stephen23 il 19 Gen 2016
Modificato: Stephen23 il 19 Gen 2016
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.
Daniel
Daniel il 19 Gen 2016
nevermind, I think I figured out my issue

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by