Method metadata InputNames does not work with arguments block
Afficher commentaires plus anciens
For TestClass1:
classdef TestClass1
methods
function obj = TestClass1(a,b)
end
end
end
The metadata for the constructor shows the input list:
tc=TestClass1(1,2);
meta=metaclass(tc);
meta.MethodList(1).InputNames
If I have an arguments block:
classdef TestClass2
methods
function obj = TestClass2(a,b)
arguments
a
b
end
end
end
end
Then the metadata thinks I have varargin:
tc = TestClass2(1,2);
meta=metaclass(tc);
meta.MethodList(1).InputNames
So... is this expected behavior? Is there a fundamental reason the metadata doesn't show something more useful? Are there some conditions where we can use an arguments block and get useful metadata for the constructor?
1 commentaire
AB
le 19 Fév 2026 à 21:19
Réponses (1)
Raag
il y a environ 8 heures
0 votes
Hi,
It is my understanding that you are observing that when using an arguments block in a class constructor, the metadata InputNames property returns {'varargin'} instead of the actual parameter names you defined, whereas constructors without the arguments block correctly report the individual input names.
This behavior appears to be a limitation in how MATLAB's metaclass reflection system currently handles methods that use arguments validation blocks. When an arguments block is present, the metadata reflects the function signature as if it accepts variable arguments, even though you have explicitly named parameters inside the validation block.
There does not appear to be a standard workaround to retrieve the correct parameter names from the InputNames property when an arguments block is used. If programmatic access to input parameter names via metaclass is essential for your application, you may need to either define the parameters directly in the function signature without using an arguments block, or maintain a separate record of parameter names in your class documentation or properties.
If this limitation impacts your workflow, I would recommend reaching out to MathWorks Technical Support to report your use case and request enhancement consideration for future releases.
For more details, refer:
- Function argument validation: https://www.mathworks.com/help/matlab/ref/arguments.html
- MathWorks Support: https://www.mathworks.com/support/contact_us.html
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!