if else is not working correctly inside parfor loop

If I run the following piece of code using for loop, it woks fine. But when I am using the same with parfor I get an error.
Code snippet:
vhFlag = 3;
nCores = 8;
matlabpool(nCores)
parfor id = 1 : obj.patchNum
if(3 == vhFlag)
% fetch each patch from the list for matrix creation
patch = testMat(:,:,id);
else
% randomely choose a patch id
patchCounter = ceil(rand(1) * 100);
% get the corresponding patch (original or resynthesized)
patch = StimuliGeneration.GetAPatch(patchListBest, ...
patchCounter, sz-1,
vhFlag);
testMat(:,:,id) = patch; %%to test
end
mat(:, id) = patch(:);
end
matlabpool close
Error : Starting matlabpool using the 'local' configuration ... connected to 8 labs.
??? Undefined function or variable "patchListBest".
Error in => StimuliGeneration>StimuliGeneration.CreatePatchMatrix at 48
parfor id = 1: obj.patchNum

Answers (0)

Categories

Asked:

on 10 Jul 2013

Community Treasure Hunt

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

Start Hunting!