Rowfun Too Many Outputs

4 次查看(过去 30 天)
amen45
amen45 2017-3-7
评论: amen45 2017-3-7
I have a table, mod_table, with columns Name,On,Export,Xls,and Directory. I'm trying to run the following:
rowfun(@delete_temp_dirs,mod_table)
using a helper function, delete_temp_dirs, which is below:
function delete_temp_dirs (mod_names,mod_on,mod_export_on,mod_xls_on,mod_dir)
if (mod_on ~= mod_export_on) && isdir(mod_dir{1})
disp('tags different')
if ~mod_xls_on
rmdir(mod_dir{1},'s')
end
end
I'm getting the following error: Error using table/rowfun>dfltErrHandler (line 338) Applying the function 'delete_temp_dirs' to the 1st row of A generated the following error:
Too many output arguments.
What am I doing wrong?

采纳的回答

Steven Lord
Steven Lord 2017-3-7
Your function does not return an output. By default rowfun calls your function with one output argument, but you could specify the 'NumOutputs' parameter name with value 0 to tell rowfun to call your function with no outputs.
% Create a sample table
load patients
patients = table(LastName,Gender,Age,Height,Weight,Smoker,Systolic,Diastolic);
patients2 = patients(1:10, :);
% This rowfun call will throw an error, since why does not return any outputs
rowfun(@(varargin) why, patients2)
% This rowfun call will work, because rowfun will not expect why to return anything
rowfun(@(varargin) why, patients2, 'NumOutputs', 0)
% This calls why using the Age from the table as the answer number to display
rowfun(@why, patients2, 'NumOutputs', 0, 'InputVariables', 'Age')
% This should display the 4th answer displayed by the last rowfun call
why(patients2{4, 'Age'})

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by