for to parfor, Error: The variable h in a parfor cannot be classified.
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
Brendan Hamm
2015 年 7 月 9 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Classification についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!