for to parfor, Error: The variable h in a parfor cannot be classified.
1 view (last 30 days)
Show older comments
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?
0 Comments
Answers (1)
Brendan Hamm
on 9 Jul 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;
0 Comments
See Also
Categories
Find more on Classification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!