Borrar filtros
Borrar filtros

Parameters imported using assignin not visible to parfor

2 visualizaciones (últimos 30 días)
Yoav Livneh
Yoav Livneh el 7 de Abr. de 2014
Comentada: Yoav Livneh el 11 de Abr. de 2014
I am runnig a function that uses a structure with many fields as an input. I use assignin to import all the fields as variables to the function workspace.
When I use a regular for loop the code works fine, but when I use a parfor loop I get an error that the variables are undefined. For example:
Error using parallel_function (line 598)
Undefined function or variable 'Target_size'.
Error stack:
Main>(parfor body) at 110
Target_size is one of the variables that are imported and is the first of these to appear in the parfor loop. It gives the line number where it appears first, inside the parfor loop.
I have noticed that the error only occurs in a function. If I run the code as a script it works fine.
Is there a way around this? Or maybe is there a better way to import many structure fields as variables to the workspace at once?
Thanks.

Respuesta aceptada

Edric Ellis
Edric Ellis el 11 de Abr. de 2014
PARFOR requires that you pass all variables explicitly - as you have discovered, it does not understand constructs like ASSIGNIN. If your PARFOR loop is inside a function, the best way to proceed would be to pass all the arguments required for that loop as input arguments to the function.
  1 comentario
Yoav Livneh
Yoav Livneh el 11 de Abr. de 2014
Thanks for the response. I figures out this limitation of parfor the hard way. What I ended up doing is calling another function inside the loop, where I can use assignin.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by