How can I change this code to be able to use parfor?

2 次查看(过去 30 天)
A=randn(5,1);
parfor i=1:4
B=randn(3,1);
for t=1:size(B,1)
for w=1:size(A,1)
if B(t)==A(w)
A(w)=A(w)+1;
end
end
end
end

回答(1 个)

Matt J
Matt J 2013-10-31
编辑:Matt J 2013-10-31
A=randn(5,1);
C=cell(1,4);
parfor i=1:4
B=randn(1,3);
C{i}=sum(bsxfun(@eq,A,B),2);
end
A=A+sum([C{:}],2);

类别

Help CenterFile Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by