Clear Filters
Clear Filters

Rowfun Too Many Outputs

4 views (last 30 days)
amen45
amen45 on 7 Mar 2017
Commented: amen45 on 7 Mar 2017
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?

Accepted Answer

Steven Lord
Steven Lord on 7 Mar 2017
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'})
  1 Comment
amen45
amen45 on 7 Mar 2017
Thank you! This is very helpful!

Sign in to comment.

More Answers (0)

Categories

Find more on Tables in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!