inline function returning multiple output variables

8 visualizaciones (últimos 30 días)
Pete sherer
Pete sherer el 25 de Ag. de 2023
Comentada: Pete sherer el 25 de Ag. de 2023
tdata = table(["US";"US";"US";"UK";"UK";"TW";"TW";"TW";"TW"], [1;1;5;1.20000000000000;3;4;5;1;2],'VariableNames',{'name','Loss'});
tecdf = @(x) ecdf( x, 'Function', 'survivor');
tout = varfun( tecdf, tdata, 'GroupingVariables','name','Input','Loss')
tout = 11×3 table
name GroupCount Fun_Loss ____ __________ ________ "TW" 4 1 "TW" 4 0.75 "TW" 4 0.5 "TW" 4 0.25 "TW" 4 0 "UK" 2 1 "UK" 2 0.5 "UK" 2 0 "US" 3 1 "US" 3 0.33333 "US" 3 0
tout only contains the first output from ecdf function. Is there a way to have it returns both output variables?
Thanks,

Respuesta aceptada

Matt J
Matt J el 25 de Ag. de 2023
Editada: Matt J el 25 de Ag. de 2023
A wrapper is needed.
tdata = table(["US";"US";"US";"UK";"UK";"TW";"TW";"TW";"TW"], [1;1;5;1.20000000000000;3;4;5;1;2],'VariableNames',{'name','Loss'});
tecdf = @(x) ecdfWrapper( x, 'Function', 'survivor');
tout = varfun( tecdf, tdata, 'GroupingVariables','name','Input','Loss')
tout = 11×3 table
name GroupCount Fun_Loss ____ __________ __________________ "TW" 4 1 1 "TW" 4 0.75 1 "TW" 4 0.5 2 "TW" 4 0.25 4 "TW" 4 0 5 "UK" 2 1 1.2 "UK" 2 0.5 1.2 "UK" 2 0 3 "US" 3 1 1 "US" 3 0.33333 1 "US" 3 0 5
function out=ecdfWrapper(x,varargin)
[o1,o2]=ecdf( x, varargin{:});
out=[o1,o2];
end
  3 comentarios
Image Analyst
Image Analyst el 25 de Ag. de 2023
Rather than have to have an anonymous function use a wrapper function, why not just make the anonymous function into a regular function? Then there's no need for the anonymous function anymore.
Pete sherer
Pete sherer el 25 de Ag. de 2023
Thanks vey much

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Function Creation en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by