parfor error with 3d matrix
2 views (last 30 days)
Show older comments
Ahmet Ayan
on 5 May 2019
Answered: Walter Roberson
on 5 May 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
0 Comments
Accepted Answer
Walter Roberson
on 5 May 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
0 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!