Error: The variable in a parfor cannot be classified.
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
0 commentaires
Réponses (1)
Matt J
le 16 Nov 2017
Modifié(e) : Matt J
le 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 commentaires
Walter Roberson
le 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.
Voir également
Catégories
En savoir plus sur Matrix Indexing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!