Using a Variable calculated in a parfor loop

I am calculating the internal forces of the finite elements in a mesh inside a parfor loop:
parfor iel=1:nel
id_1 = Connect(iel,1); % ID of 1st Node
id_2 = Connect(iel,2); % ID of 2nd Node
area = Connect(iel,3); % extract cross-sectional area
el_disp = [U(gdl_n*id_1-(gdl_n-1):gdl_n*id_1,1); U(gdl_n*id_2-(gdl_n-1):gdl_n*id_2,1)]; % Element Displacement Vector [U_i U_j]
[qi{iel,1}] = Internal_Forces(id_1,id_2,el_disp,area,mechanical_parameters];
end
I am storing the internal forces 'qi' in a cell. This operation is performed correctly, but then I am unable to use the so calculated variable outside such loop (I am trying to use it as the input for a function). Any ideas?

댓글 수: 3

Edric Ellis
Edric Ellis 2015년 11월 26일
Are you trying to use the elements of qi outside the loop? That should be fine, what is the problem you're experiencing?
Alessandro
Alessandro 2015년 12월 14일
Yes, I am. I receive an error saying that the variable cannot be used outside the parfor loop (will give you more details when I get back to work)!
Does the problem change if you use
qi{iel,1} = Internal_Forces(id_1,id_2,el_disp,area,mechanical_parameters];
without the []?
Also, in the code you posted you have a carriage return between mechanical_parameters and the ] that follows it.

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

도움말 센터File Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

질문:

2015년 11월 25일

댓글:

2015년 12월 14일

Community Treasure Hunt

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

Start Hunting!

Translated by