Why does the sum not defined error happen when using mean(table col) inside a parlor loop?
2 次查看(过去 30 天)
显示 更早的评论
New to the Parallel Tool Box and confused by the results below. Can anyone explain to me why this error happens? It appears to me that the tool box doesn't support the table data type vary well, but since I'm new to this portion of MATLAB, I wanted to get other opinions.
clear all, clc
% TEST
% Nathan Kamphuis May 2014
n=10;
A = zeros(n);
b=NaN(n,1);
for i=1:n,
for j=1:n,
A(i,j)=i+j-1;
end
end
% B=A; % causes no error with line 16
B=array2table(A); % causes error with line 16
parfor i=1:n,
b(i,1)=mean(B(i,:));
% b(i,1)=mean(B{i,:}); Causes no error with either line 13 or 14
end
Analyzing and transferring files to the workers ...done.
Error using mean (line 82)
An UndefinedFunction error was thrown on the workers for 'sum'. This might be because
the file containing 'sum' 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.
Error in Mean_Test (line 15)
parfor i=1:n,
Caused by:
Undefined function 'sum' for input arguments of type 'table'.
0 个评论
回答(1 个)
Edric Ellis
2014-5-9
I get the same error when using a FOR loop. Perhaps you're missing a call to TABLE2ARRAY? I.e.
parfor ...
b(i,1)=mean(table2array(B(i,:)));
end
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!