Unclassified variables in a parfor loop

1 Ansicht (letzte 30 Tage)
oceanmod
oceanmod am 16 Mär. 2020
Kommentiert: Matt J am 17 Mär. 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 Kommentar
Mohammad Sami
Mohammad Sami am 17 Mär. 2020
Try initializing variable C before calling the parfor loop.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 17 Mär. 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 Kommentare
oceanmod
oceanmod am 17 Mär. 2020
Thanks! Is there a reason why changing the loop index like this fixes the problem?
Matt J
Matt J am 17 Mär. 2020
It satisfies restrictions on sliced variables listed here

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by