Filter löschen
Filter löschen

Rowfun Too Many Outputs

4 Ansichten (letzte 30 Tage)
amen45
amen45 am 7 Mär. 2017
Kommentiert: amen45 am 7 Mär. 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?

Akzeptierte Antwort

Steven Lord
Steven Lord am 7 Mär. 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 Kommentar
amen45
amen45 am 7 Mär. 2017
Thank you! This is very helpful!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Tables finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by