What's wrong with this parfor loop?
Show older comments
When I try to run the following parfor loop, Matlab returns the error claiming that A cannot be classified.
N = 10;
T = 3;
A = zeros(N,T);
parfor i = 1:1:N
for t = 1:1:T
A(i,t) = rand(1,1);
end
end
Why isn't A considered to be a sliced output variable? The following modification works just fine.
N = 10;
T = 3;
A = zeros(N,T);
parfor i = 1:1:N
A(i,1) = rand(1,1);
end
So it seems to be something to do with the inner loop over t. From reading the help document on sliced variables, I don't understand why this inner loop would make a difference.
Accepted Answer
More Answers (1)
Walter Roberson
on 11 Dec 2015
N = 10;
T = 3;
A = zeros(N,T);
parfor i = 1:1:N
v = zeros(1,T);
for t = 1:1:T
v(1,t) = rand(1,1);
end
A(i, :) = v;
end
1 Comment
even coil
on 11 Dec 2015
Categories
Find more on Resizing and Reshaping Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!