Question about parfor nested loop
이전 댓글 표시
Hi,
I have a question about the nested parfor loop. Please see the following codes:
clc
clear
parfor i=1:3
for j=1:3
if j<2
B(i,j)=j;
end
end
end
The result of this code should be B=[1;1;1], but the Matlab gives B=[1,1,1;1,1,1;1,1,1]. I have been confused by this problem for a long time and thank you in advance if you have some time to look into the problem.
Haonan
댓글 수: 7
Walter Roberson
2021년 1월 1일
When I test, I get [1;1;1] as you expected.
haonan He
2021년 1월 1일
clc
clear
parfor i=1:3
for j=1:3
if j<2
B(i,j)=j;
end
end
end
B
Can you also check this?
B = (0);
parfor ii=1:3
for jj=1:3
if jj<2
B(ii,jj)=jj;
end
end
end
disp(size(B))
haonan He
2021년 1월 2일
haonan He
2021년 1월 2일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Surrogate Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
