classification error: slicing struct for parfor loop

3 views (last 30 days)
Jonathan on 2 Jul 2014
Commented: Jonathan on 2 Jul 2014
I'm trying to run several calibrations in parallel, however even after slicing all the variables I still get the error: The variable parforloopData in a parfor cannot be classified. Here's the abbreviated code:
parfor (i=1:size(uniqueDates,1))
if( parforloopData(i,1).skip == 0 )
while (parforloopData(i,1).gbest > DEParams.VTR)
% start differential evolution
[parforloopData(i,1).bestmem, parforloopData(i,1).bestval, parforloopData(i,1).bestFctParams, parforloopData(i,1).iterno, parforloopData(i,1).pop] = differentialevolution( DEParams, paramDefCell, objFctHandle, parforloopData(i,1), parforloopData(i,1).objFctParams, emailParams, optimInfo);
parforloopData(i,1).gbest = parforloopData(i,1).bestval;
parforloopData(i,1).ObjectiveFunction = @(x) SVJObjFunDEGulli(parforloopData(i,1), x);
[parforloopData(i,1).posbestSet, parforloopData(i,1).posgbest,parforloopData(i,1).exitflag, parforloopData(i,1).output] = fminsearch(parforloopData(i,1).ObjectiveFunction, parforloopData(i,1).pop(k,:));
if (parforloopData(i,1).posgbest < parforloopData(i,1).gbest)
parforloopData(i,1).bestSet = parforloopData(i,1).posbestSet;
parforloopData(i,1).gbest = parforloopData(i,1).posgbest;
if ( abs(parforloopData(i,1).bestLocalMinimum - parforloopData(i,1).gbest) > reseterrgrad)
parforloopData(i,1).bestLocalMinimum = parforloopData(i,1).gbest
parforloopData(i,1).newSet = minbound+(maxbound-minbound).*rand(1,8);
while (~checkStartingValuesDifference(parforloopData(i,1).newSet,parforloopData(i,1).startingValuesMatrix, diffInStartingValues ))
parforloopData(i,1).newSet = minbound+(maxbound-minbound).*rand(1,8);
parforloopData(i,1).startingValuesMatrix(end+1,:) = parforloopData(i,1).newSet;
parforloopData(i,1).objFctParams.V0 = parforloopData(i,1).newSet(1)
optimParams(i,:) = [uniqueDates(i) parforloopData(i,1).bestSet parforloopData(i,1).gbest];
parforloopData is a struct, which has many of its variables entered in a previous normal loop. I don't really understand why I get the error here, since each loop works on its own slice of parforloopData

Accepted Answer

Jill Reese
Jill Reese on 2 Jul 2014
It might help to store parforloopData(i,1) in a temporary variable inside the loop, use the temporary variable everywhere, and then update parforloopData(i,1) with the value of the temporary before exiting the parfor loop.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!