parfor error with 3d matrix

1 次查看(过去 30 天)
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

采纳的回答

Walter Roberson
Walter Roberson 2019-5-5
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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by