Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
MRC
MRC el 31 de Oct. de 2013
Comentada: Matt J el 1 de Nov. de 2013
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

Respuestas (1)

Matt J
Matt J el 31 de Oct. de 2013
Editada: Matt J el 31 de Oct. de 2013
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);
  1 comentario
Matt J
Matt J el 1 de Nov. de 2013
Better:
A=randn(5,1);
C=0;
parfor i=1:4
B=randn(1,3);
C=C+sum(bsxfun(@eq,A,B),2);
end
A=A+C;

Iniciar sesión para comentar.

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by