About PARFOR using 2d array
Mostra commenti meno recenti
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!
Risposte (2)
Edric Ellis
il 31 Mar 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
il 1 Apr 2015
2 Commenti
Edric Ellis
il 1 Apr 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
il 11 Mar 2017
Categorie
Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!