Filter löschen
Filter löschen

Error: The variable Agent in a parfor cannot be classified

1 Ansicht (letzte 30 Tage)
Veronika Mazulina
Veronika Mazulina am 28 Jan. 2020
Beantwortet: Jemima Pulipati am 22 Dez. 2020
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.

Antworten (1)

Jemima Pulipati
Jemima Pulipati am 22 Dez. 2020
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:

Kategorien

Mehr zu Parallel Computing Fundamentals finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by