필터 지우기
필터 지우기

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 CenterFile Exchange에서 Tables에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by