MATLAB: Parfor cannot run due to the way the variable ‘Adj_Load_Mat’ is used

finite element assemblyparfor

Hello,
I am trying to run the following parfor loop, but I keep getting an error. The error message says "parfor cannot run due to the way the variable 'Adj_Load_Mat' is used." Any workaround is highly appreciated.
Adj_Load_Mat=zeros(tne,ndof);
parfor iel=1:tne
dof=dof2(iel,:);
Adj_Load_Mat(iel,dof)=(Ad_Load_e(iel,:))';
end
Adj_Load=sum(Adj_Load_Mat,1);
The arrays 'Ad_Load_e' and 'dof2' are calculated at previous steps.
Thanks in advance

Best Answer

Try
Adj_Load_Mat=zeros(tne,ndof);
parfor iel=1:tne
dof=dof2(iel,:);
local_Adj = Adj_Load_Mat(iel, :);
%it has to end up as column the transpose portion of ' must be
%irrelevant so you must have used ' to indicate conjugate
local_Adj(dof) = conj(Ad_Load_e(iel, :));
Adj_Load_Mat(iel,:) = local_Adj;
end
Adj_Load=sum(Adj_Load_Mat,1);