필터 지우기
필터 지우기

parfor for double iteration??

조회 수: 7 (최근 30일)
Jinsoo
Jinsoo 2013년 8월 23일
Dear, I want to make a matrix G(m, n) as follows:
gamma = sqrt(sqrt(k/(E*I))); % gamma
G = zeros(length(x),length(qusi));
parfor n1 = 1:length(x)
for n2 = 1:length(qusi)
qua = gamma*abs(qusi(n2)-x(n1))/sqrt(2);
G(n1,n2) = (gamma/(2*k))*exp(-qua)*sin(qua + pi/4); % G(x,qusi)
end
end
However, the error come up as follows:
Error using testsquare_test (line 53)
Error: The variable G in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
I can't understand it. How should I do?
Could you please help me?
  댓글 수: 1
Khoo
Khoo 2013년 8월 23일
Are you using the parallel computing from matlabpool? parfor is same as for-loop but it's in parallel computing.

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

채택된 답변

Edric Ellis
Edric Ellis 2013년 8월 27일
Unfortunately, PARFOR doesn't understand how you're accessing 'G' even though you are using it in an order-independent way. What you need to do is build up a temporary row, and then assign it to the row of 'G' all in one go:
parfor n1 = 1:length(x)
tempRow = zeros(1, length(qusi));
for n2 = 1:length(qusi)
qua = gamma*abs(qusi(n2)-x(n1))/sqrt(2);
tempRow(n2) = (gamma/(2*k))*exp(-qua)*sin(qua + pi/4);
end
G(n1, :) = tempRow;
end
  댓글 수: 1
Jinsoo
Jinsoo 2013년 9월 4일
Thank you very much.

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

추가 답변 (1개)

Madhura Suresh
Madhura Suresh 2013년 8월 26일
You will need to slice/classify your variables in parfor loops. Look at this blog:
  댓글 수: 1
Jinsoo
Jinsoo 2013년 9월 4일
Thank you very much.

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

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by