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 个评论

Can your EscapeVelocity routine be rewritten to be vectorized, passing in an entire vector of y values at once?
Yes it can easily, I think.

请先登录,再进行评论。

 采纳的回答

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
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