About PARFOR using 2d array
显示 更早的评论
Dear all,
I'm trying to use a parfor in the 2d array with the code below:
parfor j = 1:6000
for k = 1:8100
SR(k+8100,j+6000,1) = CAM04R(k,j,1);
SG(k+8100,j+6000,2) = CAM04G(k,j,1);
SB(k+8100,j+6000,3) = CAM04B(k,j,1);
end
end
But the Matlab its showing the follow messages:
The parfor loop cannot run due to the way variable 'SR' is used
The parfor loop cannot run due to the way variable 'SG' is used
The parfor loop cannot run due to the way variable 'SB' is used
Any suggestion about how I can try to fix this?
Thanks!
回答(2 个)
Edric Ellis
2015-3-31
To make SR, SG, and SB be "sliced" output variables from the parfor loop, you need to follow the rules described here. Basically, you need to remove the offset to the indexing expressions. For example, the following works just fine:
parfor i = 1:10
for j = 1:10
x(j, i, :) = rand(3,1);
end
end
Leonardo Filho
2015-4-1
2 个评论
Edric Ellis
2015-4-1
If that's all you are doing inside parfor, it's surely much quicker to use indexing expressions like so:
S(8101:16200, 1:6000, :) = CAM01(1:8100, 1:6000, :);
S(1:8100, 1:6000, :) = CAM02(1:8100, 1:6000, :);
S(1:8100, 6001:12000, :) = CAM03(1:8100, 1:6000, :);
S(8101:16200, 6001:12000, :) = CAM04(1:8100, 1:6000, :);
(I'm not sure why parfor can handle one offset but not two...)
Leonardo Filho
2017-3-11
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!