replacing the for loops Please

count = 1;
for n = 2: 97
for m = 2:length(time)
for i=3:numApRH
for j=2:numRawRH
for p = 2:numMapPT
PT_load(count, 1) = date=ap{m,1};
PT_load(count, 2) = t=ap{n,2};;
PT_load(count, 3) = raw{j,1};
PT_load(count, 4) = raw{j,3}*ap{m,i};
PT_load(count, 5) = map{p,32};
PT_load(count, 6) = map{p,33};
count = count + 1;
end
end
end
end
end
end
end
end

1 comentario

Jan
Jan el 21 de Jul. de 2017
Editada: Jan el 21 de Jul. de 2017
You forgot to ask a question.

Iniciar sesión para comentar.

 Respuesta aceptada

Jan
Jan el 21 de Jul. de 2017
Editada: Jan el 21 de Jul. de 2017
If you want to increase the speed, care for pre-allocating PT_load.
Then avoid repeated work inside the loops:
count = 0;
PT_load = zeros(96 * (length(time) - 1) * (numApRH - 2) * ...
(numRawRH - 1) * (numMapPT - 1), 6);
q = zeros(1,6);
for n = 2: 97
q(2) = ap{n,2};
for m = 2:length(time)
q(1) = ap{m,1};
for i = 3:numApRH
ap_mi = ap{m,i};
for j = 2:numRawRH
q(3) = raw{j,1};
q(4) = raw{j,3} * ap_mi;
for p = 2:numMapPT
% ??? PT_load(count, 1) = date=ap{m,1}; ???
% Where does the "date =" come from? It is invalid syntax!
% ??? PT_load(count, 2) = t=ap{n,2};; ???
% Same for "t=" ???
q(5) = map{p,32};
q(6) = map{p,33};
count = count + 1;
PT_load(count, :) = q;
end
end
end
end
end
Ups: There are 3 "end" too much in the code. Please post working code only.
Now compare the speed and decide, if this is still the bottleneck of your code.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

pg
el 21 de Jul. de 2017

Editada:

Jan
el 21 de Jul. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by