필터 지우기
필터 지우기

parfor loop and decimal step increments in variable

조회 수: 1 (최근 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.

추가 답변 (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