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

 采纳的回答

Jan
Jan 2017-7-21
编辑:Jan 2017-7-21
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.

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Loops and Conditional Statements 的更多信息

提问:

pg
2017-7-21

编辑:

Jan
2017-7-21

Community Treasure Hunt

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

Start Hunting!

Translated by