parfor loop and decimal step increments in variable

2 ビュー (過去 30 日間)
IDN
IDN 2021 年 12 月 30 日
コメント済み: IDN 2021 年 12 月 30 日
Hello, What is the best way to be able to use a "parfor" loop when you have a variable that uses a decimal step as below...
yHH = 1:0.1:3;
parfor yA = 3:6
for yC = 10:20
for yHper = 2:5
for yH = 1:length(yHH)
for yV = 50:60
Function(yA,yC,yHper,yH,yV);
end
end
end
end
end
Thanks!

採用された回答

Walter Roberson
Walter Roberson 2021 年 12 月 30 日
yH_vals = 1:0.1:3; n_yH = length(yH_vals);
yA_vals = 3:6; n_yA = length(yA_vals);
yC_vals = 10:20; n_yC = length(yC_vals);
yHper_vals = 2:5; n_yHper = length(yHper_vals);
yV_vals = 50:60; n_yV = length(yV_vals);
parfor yAidx = 1:n_yA
yA = yA_vals(yAidx);
for yCidx = 1:n_yC
yC = yC_vals(yCidx);
for yHperidx = 1:n_yHper
yHper = yHper_vals(yHperidx);
for yHidx = 1:n_yH
yH = yH_vals(yHidx);
for yVidx = 1 : n_yV
yV = yV_vals(yVidx);
YourOutput(yVidx, yHidx, yHperidx, yCidx, yAidx) = YourFunction(yA, yC, yHper, yH, yV);
end
end
end
end
end
And if you really want, then afterwards,
YourOutput = permute(YourOutput, [6 5 4 3 2 1]);
Using the inner loop variable as the first index is most efficient for memory access; especially with multidimensional arrays, the difference can be quite notable.
  1 件のコメント
IDN
IDN 2021 年 12 月 30 日
Perfect thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by