Error: The variable Agent in a parfor cannot be classified

조회 수: 1 (최근 30일)
Veronika Mazulina
Veronika Mazulina 2020년 1월 28일
답변: Jemima Pulipati 2020년 12월 22일
parfor ii = 1:Workspace.Number_of_Compartments
Comp(ii).Vehicles = zeros(length(Compartment(ii).Vehicles),2)
for jj = 1:length(Compartment(ii).Vehicles)
Veh_ID = Compartment(ii).Vehicles(jj);
for zz = 1:length(Agent(Veh_ID).Structure.Following_Compartment)
if (Agent(Veh_ID).Structure.Following_Compartment(zz) == ...
Agent(Veh_ID).Structure.Current_Compartment)
Agent(Veh_ID).Structure.Local_Task = [Agent(Veh_ID).Structure.Local_Task,...
Agent(Veh_ID).Structure.Global_Task_Zones(zz)];
else
cur_comp = Agent(Veh_ID).Structure.Current_Compartment;
fol_comp = Agent(Veh_ID).Structure.Following_Compartment(zz);
Find1 = find(Compartment(cur_comp).Following_Compartment == fol_comp);
% All elements of the Find1 row of the field Exite_Nodes of
% the Compartment(cur_comp)
Find2 = Compartment(cur_comp).Exite_Nodes(Find1,:);
Find2_1 = find(Find2 ~= 0);
Find3 = find(Compartment(cur_comp).Exite_Nodes_State(Find1,:) == 0);
Find4 = intersect(Find2_1,Find3);
Find4 = Find4(randi(length(Find4)));
Agent(Veh_ID).Structure.Local_Task = [Agent(Veh_ID).Structure.Local_Task,...
Find2(Find4)];
end
end
end
How to eliminate this error? I need to add data in the structure inside parfor loop.

답변 (1개)

Jemima Pulipati
Jemima Pulipati 2020년 12월 22일
Hello,
From my understanding, you are using the 'Agent' variable for slicing as well as indexing and trying to assign a value to it. This error arises because once you index a variable you cannot use it anywhere else in the parfor loop.
The suggested workaround would be to use a temporary variable inside the for loops and one 'Agent' variable that gets assigned the required values in the main parfor loop. In this way the variable 'Agent' would be referenced only once in the entire parfor loop.
Some answers from the community which might be of relevance to you are:

카테고리

Help CenterFile Exchange에서 Parallel Computing Fundamentals에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by