Classification in Parfor Loops

parfor xIndex=1:2:c
for yIndex=1:2:c
x = xvec(xIndex);
y = yvec(yIndex);
M(xIndex, yIndex) = EscapeVelocity(-0.123+0.745*1i, x+y*1i, m);
end
end
MatLab says "The variable M in a parfor cannot be classified"
I would appreciate any explanation of why this occurs and how to correct it.

댓글 수: 2

Walter Roberson
Walter Roberson 2013년 2월 16일
Can your EscapeVelocity routine be rewritten to be vectorized, passing in an entire vector of y values at once?
Edwin
Edwin 2013년 2월 16일
Yes it can easily, I think.

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

 채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 16일

0 개 추천

Try constructing
xvec2 = xvec(1:2:c);
nxvec2 = length(xvec2);
yvec2 = yvec(1:2:c);
nyvec2 = length(yvec2);
M2 = zeros(nxvec2, nyvec2);
Then
parfor for xindex = 1 : nxvec2
x = xvec2(xindex);
for yindex = 1 : nyvec2
y = yvec2(yindex);
M2(xIndex, yIndex) = EscapeVelocity(-0.123+0.745*1i, x+y*1i, m);
end
end
Then
M(1:2:c, 1:2:c) = M2;

댓글 수: 2

As xvec and yvec were the same I have just made a general xvec. Selected parts of Code now read xvec2 = xvec(1:2:c);
n1 = length(xvec2);
M2 = zeros(n1, n1);
parfor xIndex=1:n1
for yIndex=1:n1
x = xvec2(xIndex);
y = xvec2(yIndex);
M2(2*xIndex-1, 2*yIndex-1) = EscapeVelocity2(-0.123+0.745*1i, x+y*1i, m);
end
end
Edwin
Edwin 2013년 2월 16일
Got rid of the 2 and -1, they were from trying to mold your code to my uses. Thank you very much for your time.

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

추가 답변 (0개)

카테고리

도움말 센터File 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