Using a logical variable in parfor

2 visualizaciones (últimos 30 días)
Adam R Mangel
Adam R Mangel el 18 de En. de 2018
Respondida: Adam R Mangel el 18 de En. de 2018
I have some logical variable I'm setting outside of a parfor loop, then using the logical variable inside the parfor loop for an if statement. When the logical value is false, the calculation inside the if statement is still executing. Even if I negate the variable, the condition inside the if statement is executed. It's like the if statement isn't being evaluated. I'm sure I have some bad structure here; how can I use the logical variable inside the parfor loop?
logicalvar = false;
if logicalvar
%initialize var2
end
parfor i = 1:10
[var] = calculatevar(withinputvariables);
if logicalvar
var2 = var2 + var;
end
end
  1 comentario
Walter Roberson
Walter Roberson el 18 de En. de 2018
Which version are you using? The problem did not show up in a quick test for me in R2017b:
logicalvar = false;
if logicalvar; var2 = 0; end
parfor i = 1 : 10; temp = rand; if logicalvar; var2 = var2 + temp; end; end
var2
var2 properly comes out as undefined.

Iniciar sesión para comentar.

Respuestas (1)

Adam R Mangel
Adam R Mangel el 18 de En. de 2018
2017b

Categorías

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

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by