フィルターのクリア

question on using parfor

1 回表示 (過去 30 日間)
Baozai
Baozai 2016 年 11 月 22 日
コメント済み: Alexandra Harkai 2016 年 11 月 24 日
Hello, all.
I got a question on using parfor in matlab. When I tried to run the following code, I got an error showing:"Error: The variable Resp in a parfor cannot be classified.". Is this because Resp will be generated simultaneously when jjjj will be executed parallelly? If so, does this mean I can not perform this since different Phi use the same Resp as the first structure name? Will there be any idea on solving this problem? Thank you very much.
The following are the codes:
sizePhiValuep = 7;
sizeMassp = 20;
parfor (jjjj=1:sizePhiValuep,7)
Resp.(sprintf('Phi%d',jjjj)).MaxX2RespBegin_beta= zeros(sizeMassp,1);
Resp.(sprintf('Phi%d',jjjj)).MaxX2RespEnd_beta= zeros(sizeMassp,1);
end

採用された回答

Alexandra Harkai
Alexandra Harkai 2016 年 11 月 22 日
The error message refers to the variable classification when using parfor: classification-of-variables-in-parfor-loops. It doesn't know if you'll operate on segments in each loop or accumulate values regardless of the iteration order.
You could make Resp-something an array (or two arrays, if you need Begin and End) and index into that from the corresponding loop using jjjj.

その他の回答 (1 件)

Baozai
Baozai 2016 年 11 月 23 日
Thank you, Alexandra, When I change the code to the following, it works.
sizePhiValuep = 7;
sizeMassp = 20;
parfor (jjjj=1:sizePhiValuep,7)
Resp(jjjj).Phi.MaxX2RespBegin_beta= zeros(sizeMassp,1);
Resp(jjjj).Phi.MaxX2RespEnd_beta= zeros(sizeMassp,1);
end
  1 件のコメント
Alexandra Harkai
Alexandra Harkai 2016 年 11 月 24 日
Cool.
Dynamic variable name generation for indexing purposes ( sprintf('Phi%d',jjjj) ) should be avoided anyway, so it's always good practice to use 'actual' indexing instead.

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

カテゴリ

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