About PARFOR using 2d array
Mostrar comentarios más antiguos
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!
Respuestas (2)
Edric Ellis
el 31 de Mzo. de 2015
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
el 1 de Abr. de 2015
2 comentarios
Edric Ellis
el 1 de Abr. de 2015
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
el 11 de Mzo. de 2017
Categorías
Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!