The parfor loop cannot be run due to the way variable 'J' is used
3 views (last 30 days)
Show older comments
I am receiving the following error in using parfor. Is there any way to use Parfor for here?
The parfor loop cannot be run due to the way variable 'J' is used
parfor xpop = 1:Xpop
Gxm = (X(xpop,M:Nvar)-0.5*ones(1,K)) * (X(xpop,M:Nvar)-0.5*ones(1,K))';
Cos = cos(X(xpop,1:M-1)*pi/2);
J(xpop,1) = prod(Cos)*(1+Gxm);
for nobj = 1:M-1
J(xpop,nobj+1) = (J(xpop,1)/prod(Cos(1,M-nobj:M-1)))...
* sin(X(xpop,M-nobj)*pi/2);
end
end*
Accepted Answer
Matt J
on 4 Mar 2015
Edited: Matt J
on 4 Mar 2015
There is, but it seems terribly unnecessary. Everything you are currently attempting to do with parfor is abundantly vectorizable,
xpop=1:Xpop;
Gxm=sum((X(xpop,M:Nvar)-.5).^2,2);
Cos = cos(X(xpop,1:M-1)*pi/2);
tmp1=prod(Cos,2).*(1+Gxm);
tmp2=tmp1./prod(Cos(1,M-nobj:M-1));
J(xpop,1:M)=[tmp1, bsxfun(@times,tmp2, sin(X(xpop,M-1:-1:1)*pi/2) )];
3 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!