Filter löschen
Filter löschen

Using parfor with a 3d array

8 Ansichten (letzte 30 Tage)
oceanmod
oceanmod am 3 Feb. 2021
Kommentiert: oceanmod am 3 Feb. 2021
I am trying to update a 3d array within a parfor loop. The actual code is too messy to reproduce here but the snippet of code below conveys what I am trying to do (but unable to).
a = zeros(5,5,10):
parfor t = 1:ntimes;
temp = randn(5,5); % In my actual code, this is some meaningful quantity that depends on the loop variable 't'
for k = 1:10;
a(:,:,k) = a(:,:,k) + randn(5,5);
end
end
I get an error saying matlab is unable to classiy the variable 'a'.
Is there a way I can fix this?
Thanks!

Antworten (1)

Matt J
Matt J am 3 Feb. 2021
A variable in a parfor loop must belong to one of 5 categories. I cannot tell from your simplified example which category a is supposed to belong to (and neither can parfor), but the table here should help you decide:
  6 Kommentare
Matt J
Matt J am 3 Feb. 2021
You cannot index or subscript a reduction variable.
oceanmod
oceanmod am 3 Feb. 2021
Ah, got it. Thanks again!

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange

Produkte


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by