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

114 views (last 30 days)
alpedhuez on 4 Aug 2020
Commented: alpedhuez on 5 Aug 2020
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?

Edric Ellis on 5 Aug 2020
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
alpedhuez on 5 Aug 2020
More or less.