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 件のコメント

Jan
Jan 2017 年 7 月 21 日
編集済み: Jan 2017 年 7 月 21 日
You forgot to ask a question.

サインインしてコメントする。

 採用された回答

Jan
Jan 2017 年 7 月 21 日
編集済み: Jan 2017 年 7 月 21 日

0 投票

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 ExchangeLoops 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