フィルターのクリア

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'})
  1 件のコメント
amen45
amen45 2017 年 3 月 7 日
Thank you! This is very helpful!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by