Borrar filtros
Borrar filtros

parfor loop and decimal step increments in variable

1 visualización (últimos 30 días)
IDN
IDN el 30 de Dic. de 2021
Comentada: IDN el 30 de Dic. de 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!

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de Dic. de 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.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by