Method metadata InputNames does not work with arguments block

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);
Invalid expression. Check for missing multiplication operator, missing or unbalanced delimiters, or other syntax error. To construct matrices, use brackets instead of parentheses.
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 个评论

Well I'm not sure why the code won't run, but the first output should be
ans =
2×1 cell array
{'a'}
{'b'}
and the second output should be
ans =
1×1 cell array
{'varargin'}

请先登录,再进行评论。

回答(1 个)

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:

类别

帮助中心File Exchange 中查找有关 Structures 的更多信息

产品

版本

R2024b

提问:

AB
2026-2-19,21:09

回答:

about 5 hours 前

Community Treasure Hunt

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

Start Hunting!

Translated by