classification error: slicing struct for parfor loop
3 次查看(过去 30 天)
显示 更早的评论
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;
for(k=1:size(parforloopData(i,1).pop,1))
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;
end
end
if ( abs(parforloopData(i,1).bestLocalMinimum - parforloopData(i,1).gbest) > reseterrgrad)
parforloopData(i,1).bestLocalMinimum = parforloopData(i,1).gbest
else
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);
end
parforloopData(i,1).startingValuesMatrix(end+1,:) = parforloopData(i,1).newSet;
parforloopData(i,1).objFctParams.V0 = parforloopData(i,1).newSet(1)
end
end
optimParams(i,:) = [uniqueDates(i) parforloopData(i,1).bestSet parforloopData(i,1).gbest];
end
end
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
0 个评论
采纳的回答
Jill Reese
2014-7-2
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!