How do we find the input arguments required by a handle class constructor?

조회 수: 3 (최근 30일)
I am getting an error " too many input arguments"
So I wished to match my input arguments with the constructor arguments
  댓글 수: 2
Adam
Adam 2019년 9월 20일
They are listed in the function definition of the constructor, or if there is no defined constructor then it takes 0 arguments. Since you haven't shown any class definition code or calling code it's hard to say much more though.
Vignesh Ramakrishnan
Vignesh Ramakrishnan 2019년 9월 21일
Thanks Adam. I am actually working on fixing some legacy code by my employer, so I cannot share the source code. Also, the information of 0 arguments considered by the default constructor was helpful, as I realized that the class involved had no user defined constructors.

댓글을 달려면 로그인하십시오.

채택된 답변

Guillaume
Guillaume 2019년 9월 21일
It sounds like the problem has already been resolved and as Adam said, the easiest is to look at the function definition.
If, for some reason, that's not possible, you can use the methods function (for display at the command line) with the -'full' option, or the methodsview function (for display in a separate window) to see the list of all the methods of the class and their inputs and outputs.
methods('classname', '-full')
%or
methodsview('classname')
If even more details are needed, you can also use introspection classes such as meta.class and meta.method.
%demo for class string
>> mc = meta.class.fromName('string');
>> mm = mc.MethodList(strcmp({mc.MethodList.Name}, 'string')) %find constructor in method list and display properties
mm =
method with properties:
Name: 'string'
Description: ''
DetailedDescription: ''
Access: 'public'
Static: 0
Abstract: 0
Sealed: 0
ExplicitConversion: 0
Hidden: 1
InputNames: {'rhs1'}
OutputNames: {'lhs1'}
DefiningClass: [1×1 meta.class]
Interestingly, the string constructor is hidden.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Argument Definitions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by