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

1 回表示 (過去 30 日間)
DongShin Yang
DongShin Yang 2015 年 7 月 9 日
編集済み: Edric Ellis 2015 年 7 月 10 日
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?

回答 (1 件)

Brendan Hamm
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;

カテゴリ

Help Center および File ExchangeClassification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by