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 Comment

Jan
Jan on 21 Jul 2017
Edited: Jan on 21 Jul 2017
You forgot to ask a question.

Sign in to comment.

 Accepted Answer

Jan
Jan on 21 Jul 2017
Edited: Jan on 21 Jul 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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Asked:

pg
on 21 Jul 2017

Edited:

Jan
on 21 Jul 2017

Community Treasure Hunt

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

Start Hunting!