Parameters imported using assignin not visible to parfor
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!