フィルターのクリア

argin for a class method ?

9 ビュー (過去 30 日間)
marilia15
marilia15 2012 年 3 月 13 日
fx = 'addme'; % the name of a function
nargin(fx) %returns the number of input arguments
ans =
2
I want to use "nargin" for a class method But I get an error.
fx='classname.methodname'
nargin(fx)
Error using ==> nargin
Not a valid M-file.
I want to call nargin from outside the class, for example in command window. What can I do?

採用された回答

Jacob Halbrooks
Jacob Halbrooks 2012 年 3 月 13 日
NARGIN does not currently (as of R2012a) work on class methods. However, you might be able to get the information you want by inspecting the metaclass for your class with the ? operator. For example, try:
metaInfo = ?classname
methodInfo = metaInfo.MethodList
firstMethodInputs = methodInfo(1).InputNames
For a given method, you could find the MethodList entry with a matching name and then count InputNames to get the number of inputs. You'd also want to check if the last input is named varargin.

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by