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 Commenti

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

Accedi per commentare.

 Risposta accettata

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 Commenti

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 il 16 Feb 2013
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.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by