MATLAB Answers

"unable to classify the variable in the body of the parfor-loop"

59 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2020 年 8 月 4 日
コメント済み: alpedhuez 2020 年 8 月 5 日
I tried
X=ones(b*n,5)
parfor (a=1:n, 12)
Y=X((a-1)*b+1:1:a*b,3:4);
sorted=sort(Y(:));
Z=sorted(end-2);
X((a-1)*b+1:1:a*b,5)=Z;
end
and obtained
Error: Unable to classify the variable 'bidder_samples' in the body of the parfor-loop. For more information, see Parallel for Loops in MATLAB, "Solve Variable Classification Issues in parfor-Loops".
What would be the next step?

  0 件のコメント

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

回答 (1 件)

Edric Ellis
Edric Ellis 2020 年 8 月 5 日
The doc page you mention describes the valid ways of getting results out of a parfor loop. In your case, you appear to be computing distinct chunks of column 5 of X based on chunks of columns 3:4 of X. To fit in with the parfor rules though, you must re-write your code a little to make the references into X be compatible with "slicing". One way to do that would be to make X be n-by-b-by-5, and then do something like this (completely untested):
X34 = ones(n, b, 2); % corresponds to X(:,3:4)
Xout = ones(n, b); % corresponds to X(:,5)
parfor a = 1:n
Y = X34(a,:,:);
% compute Z
Xout(a,:) = Z;
end

  3 件のコメント

alpedhuez
alpedhuez 2020 年 8 月 5 日
Essentially, is it that parfor can only deal with a single row operation?
Edric Ellis
Edric Ellis 2020 年 8 月 5 日
The restrictions of parfor sliced indexing are that you slice an array in a single dimension, and that the index in that dimension must be the loop variable (possibly with a constant offset, but that's not relevant here).
alpedhuez
alpedhuez 2020 年 8 月 5 日
More or less.

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by