Borrar filtros
Borrar filtros

Vectorization of 3 nested for loops.

1 visualización (últimos 30 días)
Emiliano Rosso
Emiliano Rosso el 6 de Sept. de 2015
Comentada: Emiliano Rosso el 7 de Sept. de 2015
I have 3 for loop and I want to vectorized it .
I try a lot to do it but I cannot do it.
This is the simple version.
I can't explain the whole situation but:
A is 100*82.
B is 203*2000.
C is 1*10.
D is 100*5*2000.
for nset=1:100
for nindy=1:5
for nimp=1:2000
if A(nset,2+(nindy-1).*3)==1
if B(33.*6+nindy,nimp)<= C(1+(nindy-1).*2)+...
((C(2+(nindy-1).*2)-C(1+(nindy-1).*2))./11).*A(nset,1+(nindy-1).*3)
D(nset,nindy,nimp)=1;
end
end
end
end
end
I want to replace the 3 for loops with vectorization...
Thanks....

Respuesta aceptada

per isakson
per isakson el 6 de Sept. de 2015
Editada: per isakson el 6 de Sept. de 2015
I don't think that your code can be vectorized. However, this should be a bit faster
for nset=1:100
for nindy=1:5
if A(nset,2+(nindy-1).*3)==1
C17 = C(1+(nindy-1).*2) ...
+ ((C(2+(nindy-1).*2)-C(1+(nindy-1).*2))./11).*A(nset,1+(nindy-1).*3);
for nimp=1:2000
if B(33.*6+nindy,nimp) <= C17
D(nset,nindy,nimp) = 1;
end
end
end
end
end
Caveat: I have neither tested correctness nor speed.
  1 comentario
Emiliano Rosso
Emiliano Rosso el 7 de Sept. de 2015
Thanks,I tried your suggestion and time was reduced by 30% !

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by