Parallel Computing Question for For loop switch to parfor
조회 수: 1 (최근 30일)
이전 댓글 표시
I am trying to find the nearest phase value to time intervals. This is the loop I have used. The matrix is large and I want to use parallel computing function 'parfor', but cannot due to having embedded functions within a function. I somewhat understand that they need things to be as simplistic as possible, but is there a way to fix this so that I can use 'parfor' function? I do not fully understand why the parallel processing has the limitations, so I am not exactly sure how to fix it.
I attached matrices for 'timeintervals' and 'phase values' if anyone needs them.
Any help would be greatly appreciated!
for i=1:length(timeintervals(:,1))
for ii=1:length(timeintervals)
[~,ix]=min(abs(timeintervals(i,ii)-phasevalues(:,2))); % find nearest location
out(i,ii)=phasevalues(ix);
end
end
댓글 수: 1
Matt J
2017년 11월 16일
but cannot due to having embedded functions within a function.
I don't see any function calls in your code.
채택된 답변
Matt J
2017년 11월 16일
편집: Matt J
2017년 11월 16일
Why not as follows?
col1=phasevalues(:,1);
col2=phasevalues(:,2); %as separate variable, repeated memory allocation is avoided
parfor j=1:size(timeintervals,2)
[~,ix]=min( abs(timeintervals(:,j).' - col2 ) ); % find nearest location
out(:,j)=col1(ix);
end
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!