What's wrong with this parfor loop?
显示 更早的评论
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.
采纳的回答
更多回答(1 个)
Walter Roberson
2015-12-11
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
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!