MATLAB Answers

Unclassified variables in a parfor loop

1 view (last 30 days)
oceanmod
oceanmod on 16 Mar 2020
Commented: Matt J on 17 Mar 2020
I am trying to do something like the following:
parfor i= xystart:xyend
....
xycount = i - xystart + 1;
A = zeros(nx,ny); B = A;
for n=1:Nn;
for m=1:Mm;
A(m,n)= <some expression>;
B(m,n)= <some expression>;
end
end
C(xycount,:,:) = A. * B;
end
I am getting an error message saying that 'C' is an unclassified variable. The above snippet is not the actual code which is quite big. But I hope the lines above convey what am I trying to do. Any idea what am I doing wrong?
Thanks!

  1 Comment

Mohammad Sami
Mohammad Sami on 17 Mar 2020
Try initializing variable C before calling the parfor loop.

Sign in to comment.

Accepted Answer

Matt J
Matt J on 17 Mar 2020
parfor i= 1:xyend-xystart+1
....
A = zeros(nx,ny); B = A;
for n=1:Nn;
for m=1:Mm;
A(m,n)= <some expression>;
B(m,n)= <some expression>;
end
end
C(i,:,:) = A. * B;
end

  2 Comments

oceanmod
oceanmod on 17 Mar 2020
Thanks! Is there a reason why changing the loop index like this fixes the problem?

Sign in to comment.

More Answers (0)