MATLAB: How can i classified the variable inside of the parfor loop

image processingImage Processing Toolboxparallel computingParallel Computing Toolbox

Sir, This is my PARFOR loop coding. I can't classified some variables in PARFOR LOOP.
parfor i1=1:1:nrr1
disp(i1);
if (varran(i1) < threshold)
labe(i1)=0;
mvqcoder(i1)=[meanranr(i1)];
mvqcodeg(i1)=[meanrang(i1)];
mvqcodeb(i1)=[meanranb(i1)];
% e=e+1;
else
labe(i1)=1;
[domr]=domsearch(rang1r(i1,:),dompoolr,gsize,ci1r(i1),ci2r(i1),ci3r(i1),msr(i1),mdr,cd1r,cd2r,cd3r,mscr);
[domg]=domsearch(rang1g(i1,:),dompoolg,gsize,ci1g(i1),ci2g(i1),ci3g(i1),msg(i1),mdg,cd1g,cd2g,cd3g,mscg);
[domb]=domsearch(rang1b(i1,:),dompoolb,gsize,ci1b(i1),ci2b(i1),ci3b(i1),msb(i1),mdb,cd1b,cd2b,cd3b,mscb);
dom=[domr,domg,domb];
[rz cz]=size(dom);
meanrar=mean(rang1r(i1,:));
meanrag=mean(rang1g(i1,:));
meanrab=mean(rang1b(i1,:));
dompolr=iCalc(dompoolr,dom,cz);
dompolg=iCalc(dompoolg,dom,cz);
dompolb=iCalc(dompoolb,dom,cz);
[isomer alphr meanrr dom1r errr]=affwerrqt(rang1r(i1,:),dompolr(1:cz,:),gsize);
[isomeg alphg meanrg dom1g errg]=affwerrqt(rang1g(i1,:),dompolg(1:cz,:),gsize);
[isomeb alphb meanrb dom1b errb]=affwerrqt(rang1b(i1,:),dompolb(1:cz,:),gsize);
cdom1r(i1)=dom(dom1r);
isome1r(i1)=isomer;
alph1r(i1)=alphr;
meanr1r(i1)=meanrar;
cdom1g(i1)=dom(dom1g);
isome1g(i1)=isomeg;
alph1g(i1)=alphg;
meanr1g(i1)=meanrag;
cdom1b(i1)=dom(dom1b);
isome1b(i1)=isomeb;
alph1b(i1)=alphb;
meanr1b(i1)=meanrab;
vqcode3r(i1,:)=[isome1r(i1),alph1r(i1),meanr1r(i1),cdom1r(i1)];
vqcode3g(i1,:)=[isome1g(i1),alph1g(i1),meanr1g(i1),cdom1g(i1)];
vqcode3b(i1,:)=[isome1b(i1),alph1b(i1),meanr1b(i1),cdom1b(i1)];
% c=c+1;
end
% w1=w1+1;
end
I got Error result
The temporary variable meanrar is used after the PARFOR loop but its value is non deterministic.
The temporary variable meanrag is used after the PARFOR loop but its value is non deterministic.
The temporary variable meanrab is used after the PARFOR loop but its value is non deterministic.
then,
The PARFOR loop can't run due to the way variable dompolr is used.
The PARFOR loop can't run due to the way variable dompolg is used.
The PARFOR loop can't run due to the way variable dompolb is used.
Please any one help this problem for parfor loop.
thank you

Best Answer

The problem is that you're building e.g. dompolr in a loop which the PARFOR machinery cannot understand. Your code currently looks a bit like this:
parfor i1 = 1:N
...
for z = 1:cz
dompolr(z,:) = dompoolr(dom(z),:);
end
...
end
I think it would fix things and simplify your code if you had instead
parfor i1 = 1:N
...
dompolr = iCalc(dompoolr,dom,cz);
...
end
...
function val = iCalc( dompoolx, dom, cz )
for z = 1:cz
val(z,:) = dompoolx(dom(z),:);
end