Converting nested for loops to vectors

2 visualizaciones (últimos 30 días)
Daniel
Daniel el 19 de En. de 2016
Editada: Stephen23 el 19 de En. de 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 comentarios
Stephen23
Stephen23 el 19 de En. de 2016
Editada: Stephen23 el 19 de En. de 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 el 19 de En. de 2016
nevermind, I think I figured out my issue

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by