Filter löschen
Filter löschen

parfor loop and decimal step increments in variable

1 Ansicht (letzte 30 Tage)
IDN
IDN am 30 Dez. 2021
Kommentiert: IDN am 30 Dez. 2021
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!

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 30 Dez. 2021
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.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by