variable H1 can not be classified in parfor-loop

6 views (last 30 days)
H1(subsizeX,subsizeY,(subnumX-1)*(subnumY-1))=zeros(subsizeX,subsizeY);
parfor ii=1:(subnumX-1)*(subnumY-1)
iiy=ceil(ii/subnumX);
iix=ii-(iiy-1)*subnumX;
i1=iix+(iiy-1)*(subnumX-1);
i2=iix+(iiy-1)*subnumX;
H1(subsizeX,subsizeY,i1)=HGroup(:,:,i2);
end
  2 Comments
N/A
N/A on 27 Jul 2018
I am not sure what the question is, but are you declaring H1 correct ?
It looks like
H1(dimension 1, dimension2, dimension 3)=zeros(dimension 1, dimension 2)
So there is simply a mismatch in dimensions.
Novince
Novince on 28 Jul 2018
Thanks anyway.The declaration seems OK, no errors reported.The following line comes with an error.
H1(subsizeX,subsizeY,i1)=HGroup(:,:,i2);

Sign in to comment.

Accepted Answer

OCDER
OCDER on 27 Jul 2018
Take a read here for "sliced variables" https://www.mathworks.com/help/distcomp/sliced-variable.html
parfor ii=1:(subnumX-1)*(subnumY-1)
iiy = ceil(ii/subnumX);
iix = ii-(iiy-1)*subnumX;
i1 = iix+(iiy-1)*(subnumX-1);
i2 = iix+(iiy-1)*subnumX;
H1(subsizeX,subsizeY,i1)=HGroup(:,:,i2); << CAN'T DO THIS.
% H1 must be accessed with respect to parfor counter variable, "ii".
% Example:
% H1{ii} = zeros(ii+1, ii); will work. H{ii} doesn't depend on H{ii+1} , etc.
% Can't change the sliced variable index via a computation either, because then
% each parallel iteration may not always be independent.
% Bad Example:
% H1(ii) = H1(ii+1); %Can't be used. H(ii) depends on H1(ii+1). Not independent for parfor.
%
end
  1 Comment
Novince
Novince on 28 Jul 2018
Thanks, OCDER.I have read the documentations about the classification of variables in parfor loop,but I still don't know how to applly them to a matrix with 3 dimensions.It seems necessary in my code that the third index have to be computed from the loop variable,and I don't know how to deal with it.

Sign in to comment.

More Answers (0)

Categories

Find more on Parallel for-Loops (parfor) 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!