Why does the sum not defined error happen when using mean(table col) inside a parlor loop?

2 ビュー (過去 30 日間)
Nathan
Nathan 2014 年 5 月 8 日
回答済み: Edric Ellis 2014 年 5 月 9 日
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'.

回答 (1 件)

Edric Ellis
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

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by