Slicing structure variable in parfor loop
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi,
I'd like to use a parfor loop instead of a for loop in some code I have written. I currently call a function within a for loop to which I input a structure 'photon'. However, I would only like to input certain entries from the fields within this structure: e.g.
%%loop over all bins
parfor bin = 1:numel(s_uniq)
% determine current step length
s_crnt = s_uniq(bin);
% create photon wight property with photons currently being simulated
photon_crnt.W = photon.W(s_int==s_crnt);
MLint tells me I cannot use 'photon' in this way and that I should slice it. I have tried to do this but continue getting this message.
I'd appreciate your help.
Thanks!
댓글 수: 0
답변 (1개)
Walter Roberson
2012년 6월 19일
Each of your loops is writing over the same fieldname in the same structure array entry, photon_crnt.W . You cannot do that unless photon_crnt is a variable that is local to the parfor loop.
If you were to write to photon_crnt(bin).W then that would be allowed by parfor; whether it makes sense for your code is something you will need to decide.
참고 항목
카테고리
Help Center 및 File Exchange에서 Microelectronics, Photonics and Nanotechnology에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!