An UndefinedFunction error was thrown on the workers with parfor

13 次查看(过去 30 天)
Hi,
I got the error
An UndefinedFunction error was thrown on the workers for 'x'. This might be because the file containing 'x' is not accessible on the workers. Use addAttachedFiles(pool, files) to specify the required files
to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Caused by: Undefined function or variable "x"
when running the simple code below. Can anyone please help me with this?
Thanks,
clear all;
clc;
parfor n=1:1
for m=1:2
x{n}(m) = 1;
end
y = x{n}(1)
end
  3 个评论
Dave Lee
Dave Lee 2018-10-19
Hi Walter,
Do you mean as below? I tried and it could run. However, Matlab highlights the error as below when I point to parfor or x (red underscores). Is that still good?
Thanks,

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2018-10-19
移动:Edric Ellis 2025-8-11
x = cell(1, 1);
before the parfor.

类别

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