Respuesta aceptada

Matt J
Matt J el 2 de Oct. de 2013
Editada: Matt J el 2 de Oct. de 2013

1 voto

Sure, especially since the outer loop is not doing anything and can be abandoned.
parfor i=1:100
x(:,i)= rand(3,1)
end

6 comentarios

freebil
freebil el 3 de Oct. de 2013
thanks for the answer but i want to parfor the first for. Is it possible?
Matt J
Matt J el 3 de Oct. de 2013
Editada: Matt J el 3 de Oct. de 2013
parfor iter=1:50
x=nan(3,100); %initialize
for i=1:100
x(:,i)= rand(3,1)
end
end
freebil
freebil el 3 de Oct. de 2013
Really thanks! But i was wrong. Sorry. I want this
parfor iter=1:50
for i=1:100
x(iter,i)= rand(3,1)
end
end
Is it possible? Sorry again
Matt J
Matt J el 3 de Oct. de 2013
Editada: Matt J el 3 de Oct. de 2013
No, it's not possible even with normal for loops. The left hand side of
x(iter,i)= rand(3,1)
is 1x1 but the rhs is 3x1.
freebil
freebil el 3 de Oct. de 2013
x(iter,i)= rand(1) with parfor??
Matt J
Matt J el 3 de Oct. de 2013
Editada: Matt J el 3 de Oct. de 2013
You can do it, but doing it without loops
x=rand(50,100);
will be faster.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Loops and Conditional Statements en Centro de ayuda y File Exchange.

Preguntada:

el 2 de Oct. de 2013

Comentada:

el 3 de Oct. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by