フィルターのクリア

data assingment issue in parfor loop

1 回表示 (過去 30 日間)
Yu Li
Yu Li 2023 年 5 月 10 日
コメント済み: Yu Li 2023 年 5 月 10 日
Hi:
I tried to assign matrix to pre-allocated variable "A" in "parfor" loop but failed, error message says: "Error: Unable to classify the variable 'A' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops"
the technical issue I'm facing is that, the "numberIdx" is a variable that needs to be determined inside the for-loop, i.e. it is not a fixed value.
is there any way to improve my script?
Thanks!
A=ones(10,10);
parfor idx=1:1:10
numberIdx=2:2:8;
A(idx,numberIdx)=0;
end

採用された回答

Walter Roberson
Walter Roberson 2023 年 5 月 10 日
A=ones(10,10);
parfor idx=1:1:10
Arow = A(idx, :) ;
numberIdx=2:2:8;
Arow(numberIdx)=0;
A(idx, :) = Arow;
end
Yes, you copy some existing elements of A "needlessly", but this programming pattern is easy for matlab to prove will work without problems.
  1 件のコメント
Yu Li
Yu Li 2023 年 5 月 10 日
thank you, it works!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by