parfor error with 3d matrix

1 visualizzazione (ultimi 30 giorni)
Ahmet Ayan
Ahmet Ayan il 5 Mag 2019
Risposto: Walter Roberson il 5 Mag 2019
I am a newbie with parfor use. Why does not the following run and give an error?
G=ones(11,11,5) ;
parfor i=1:10
v=zeros(1,5);
for j=1:5
v(j)=rand(1);
end
G(i,i,:)=v;
end

Risposta accettata

Walter Roberson
Walter Roberson il 5 Mag 2019
The parfor index variable can only appear in one index position inside the body of the loop.
Create a 2D array and extend it after the loop
G = ones(11,11,5);
G2 = ones(11, 5);
parfor i = 1 : 10
v = zeros(1,5);
for j = 1 : 5
v(j) = rand(1);
end
G2(i, :) = v;
end
for i = 1 : 11;
G(i, i, :) = G2(i, :);
end

Più risposte (0)

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by