parfor loop and decimal step increments in variable

2 次查看(过去 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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Loops 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