Error: The variable in a parfor cannot be classified.

3 次查看(过去 30 天)
parfor t=0.1:0.1:v
m=round(0.1*t);
J= (phi(m))^2*exp(-1/phi(m));
k=J*sigma/q;
Vg=v-t;
Ve= V*(1-exp(-k*t))/2;
phi(m1+1)=(Vplus-Ve)+Vg;
end
In the above code, Parfor cannot classify the variable phi. I think this might be because the variable is used as a sliced variable as well as a reduction variable. Could someone please clarify why the error might occur and how can it be resolved? Thanks

回答(1 个)

Matt J
Matt J 2017-11-16
编辑:Matt J 2017-11-16
The intent of your code is not clear, though it is likely that your problems lie in the line
phi(m1+1)=(Vplus-Ve)+Vg;
The variables m1 and Vplus are never defined. Also, you say the loop is supposed to be doing some sort of reduction, but there is no reduction operation anywhere to be seen. A reduction variable would appear on both sides of an update, as in,
X=X+1;
However, here is my best guess as to what you might be trying to do:
mvals=round(0.1*(0.1:0.1:v));
parfor i=1:length(mvals);
m=mvals(i);
J= (phi(m))^2*exp(-1/phi(m));
k=J*sigma/q;
Vg=v-t;
Ve= V*(1-exp(-k*t))/2;
subs(i)=m+1;
vals(i)=(Vplus-Ve)+Vg;
end
result=accumarray(subs,vals)
  12 个评论
Walter Roberson
Walter Roberson 2017-11-18
No. parfor can only be used when the results of any one iteration do not depend upon the results o a previous iteration. Your results for m = 2 depend upon your results for m = 1.
The point is that you were complaining that the calculation took a long time, and one of the big slowdowns in MATLAB is if you do not pre-allocate your arrays. Try again without parfor but with pre-allocation.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Matrix Indexing 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by