Filter löschen
Filter löschen

parfor error with 3d matrix

1 Ansicht (letzte 30 Tage)
Ahmet Ayan
Ahmet Ayan am 5 Mai 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

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Mai 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

Weitere Antworten (0)

Kategorien

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

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by