Wrong indexing in parfor loop
Show older comments
I tried to use parfor to change parts of a variable but receive unexpected result
d = ones(10,10);
d = repmat(d,[1 1 1 10]);
d(:,:,2,:) = .5*d(:,:,1,:);
parfor n=1:10;
d(:,:,2,n) = 2*d(:,:,2,n);
end
I expected to receive something like
d(:,:,2,:) = d(:,:,1,:);
Instead I get
d(:,:,1,:) = 2;
d(:,:,2,:) = .5;
What went wrong? Using for instead of parfor works fine.
Thanks
5 Comments
Joachim Schlosser
on 10 Nov 2015
Can you please verify your results? I correctly get all matrices with ones.
Walter Roberson
on 10 Nov 2015
Also which MATLAB version is being used on which operating system?
Andre Zeug
on 10 Nov 2015
Edited: Andre Zeug
on 10 Nov 2015
Adam Barber
on 10 Nov 2015
I was able to reproduce this on R2014a, but not R2015b on my system.
Andre Zeug
on 10 Nov 2015
Edited: Andre Zeug
on 10 Nov 2015
Answers (1)
Andre Zeug
on 11 Nov 2015
Edited: Andre Zeug
on 11 Nov 2015
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!