Filter löschen
Filter löschen

Error: The variable in a parfor cannot be classified.

1 Ansicht (letzte 30 Tage)
Himanshi Rani
Himanshi Rani am 16 Nov. 2017
Kommentiert: Himanshi Rani am 18 Nov. 2017
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

Antworten (1)

Matt J
Matt J am 16 Nov. 2017
Bearbeitet: Matt J am 16 Nov. 2017
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 Kommentare
Walter Roberson
Walter Roberson am 18 Nov. 2017
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.
Himanshi Rani
Himanshi Rani am 18 Nov. 2017
Okay thankyou. I will try that

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by