How can I use NARGIN/NARGOUT to determine the number of input/output arguments of an object method?
3 ビュー (過去 30 日間)
古いコメントを表示
MathWorks Support Team
2010 年 9 月 20 日
回答済み: Markus Leuthold
2015 年 4 月 16 日
I am trying to determine the number of input/output arguments of an object's method. When the name of any object method is passed to NARGIN/NARGOUT, the returned value is always -1 regardless of the number of inputs/outputs specified in the method signature.
The following syntax returns -1 for any MethodName:
nargout('MethodName')
採用された回答
MathWorks Support Team
2010 年 9 月 20 日
The ability to call NARGIN/NARGOUT directly on object methods is not available in MATLAB. As a workaround, specify the class and method names explicitly using the following syntax:
nargout('ClassName>ClassName.MethodName')
0 件のコメント
その他の回答 (1 件)
Markus Leuthold
2015 年 4 月 16 日
It's almost five years later and this bug still exists. Any news from Mathworks on how to handle this situation in 2015?
Example:
Class C
classdef C < handle
methods
function r=fcn1(~)
r='run fcn1';
end
function fcn2(~)
disp('run fcn2');
end
end
end
function run
function run(f)
switch nargout(f)
case 0
feval(f);
case 1
disp(feval(f));
case -1
disp('bug')
end
What I expect from the following code
>> c=C;
>> run(@c.fcn1)
run fcn1
>> run(@c.fcn2)
run fcn2
Instead I get
>> c=C;
>> run(@c.fcn1)
bug
>> run(@c.fcn2)
bug
How do you recommend to workaround in case where you want to know nargout from a function handle AND evaluate a function handle?
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Software Development Tools についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!