08478bbe8ab42777ff0cc7b893cda29ab6f05212: This fails when a class method name is identical to a function on the MATLAB search path. For example calling the method myclass.plot(), nargout will return the number of arguments of the MATLAB built-in plot function. That's why I added a bit more checking:
try
[~, funType] = which(msg('name'));
funType = strsplit(funType,' ');
if numel(funType)==2 && strcmp(funType{2},'method')
argTemp = msg('args');
className = funType{1};
if ~isempty(argTemp) && isa(argTemp{1},className)
% the function name corresponds to the
% class of the first argument
resultsize = nargout(msg('name'));
end
end
if isempty(resultsize)
resultsize = nargout(fun);
end
catch
resultsize = -1;
end
08478bbe8ab42777ff0cc7b893cda29ab6f05212: This fails when a class method name is identical to a function on the MATLAB search path. For example calling the method
myclass.plot()
, nargout will return the number of arguments of the MATLAB built-inplot
function. That's why I added a bit more checking: