for to parfor, Error: The variable h in a parfor cannot be classified.

10 visualizaciones (últimos 30 días)
DongShin Yang
DongShin Yang el 9 de Jul. de 2015
Editada: Edric Ellis el 10 de Jul. de 2015
L=128
K=10
h = zeros(L, 1);
r = randperm(L, K);
parfor i = 1:K,
h(r(i)) = randn(1,1);
end
for to parfor, Error: The variable h in a parfor cannot be classified. How can I fix the code?

Respuestas (1)

Brendan Hamm
Brendan Hamm el 9 de Jul. de 2015
You cannot assign to an index which depends on another variable inside a parfor loop. Instead you can assign to a temporary variable in the parfor loop and extract into the appropriate location outside of the loop:
L=128;
K=10;
hTemp = zeros(K, 1);
r = randperm(L, K);
parfor k = 1:K
hTemp(k) = randn(1,1);
end
h = zeros(L,1);
h(r) = hTemp;

Categorías

Más información sobre Classification en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by